Logo
(追記) (追記ここまで)

3214번 - zagrade 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB185480.000%

문제

Lets observe sequences made only of round and square brackets, i.e. characters '()[]'.

A sequence of brackets is regular if it satisfies this inductive definition:

  1. '()' and '[]' are regular sequences
  2. If A is regular, then (A) and [A] are regular sequences
  3. If A and B are regular, then AB is regular sequence

For example '()()[]', '([])[()]' and '[(())][]' are regular, while '(', '][', '[(]' and '([)]' are not regular.

The sequence of brackets is given.

In every step, one bracket is inserted at the beginning or at the end of the sequence (round or square, left or right).

Write a program that will, after each step, determine the length of the shortest regular subsequence of consecutive characters that contains the bracket added in that step.

입력

First line contains initial sequence of brackets, whose length is at most 100,000 characters.

Next line contains integer N, 1 ≤ N ≤ 100,000, a number of steps.

In each of next N lines there are integer A and character C, separated by a single space. If A is zero (0), than character C is inserted at the beginning, and if A is one (1) then C is inserted at the end.

출력

In each of N lines, you should write the length of subsequence after that step. If there is no such subsequence, write number 0.

제한

예제 입력 1

(
1
1 )

예제 출력 1

2

예제 입력 2

(]
3
1 )
0 )
0 (

예제 출력 2

0
0
2

예제 입력 3

[])
3
0 )
0 (
0 (

예제 출력 3

0
2
6

힌트

출처

Olympiad > Croatian Highschool Competitions in Informatics > 2004 > National Competition #1 - Seniors 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /