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

32493번 - PARENTHESES 서브태스크스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.3 초 1024 MB129975.000%

문제

Who doesn't love parentheses?

Sashka stumbled upon a bracket sequence $S=s_1 s_2 \dots s_{2N}$ of 2ドルN$ parentheses, from which $N$ are opening parentheses and $N$ are closing parentheses. She defines the bracket sequence's clumsiness as the minimum number of required swaps of elements to turn it into a regular parentheses sequence. The regular parentheses sequences follow these rules:

  • The empty sequence is a regular parentheses sequence.
  • $S$ is a regular non-empty parentheses sequence iff two regular sequences $A$ and $B$ exist such that $S=(+A+)+B,ドル where $+$ denotes the operation concatenation of two sequences.

Sashka wants to know the clumsiness for $Q$ such sequences $T_1, T_2, \dots,T_Q,ドル where the $i$-th of them $T_i=s_{L_i} s_{L_i+1} \dots s_{R_i}$ consists of all the elements in $S$ from position $L_i$ to $R_i$ inclusive. It is guaranteed that every sequence $T_i$ consists of equal number of opening and closing parentheses. Write a program parentheses, which answers the $Q$ questions.

입력

The first line of the standard input contains the three integers $N,ドル $Q$ and $G,ドル which describe the number of opening parentheses in the sequence, the number of questions and the number of the subtask that the test is from. The second line contains 2ドルN$ parentheses, $s_1 s_2 \dots s_{2N}$ respectively. The last $Q$ lines of the standard input contain the integers $L_i$ and $R_i,ドル which describe the positions for the $i$-th question.

출력

On the standard output print one number on each line, the $i$-th number being the minimum number of required swaps to turn $T_i$ into a regular parentheses sequence.

제한

  • 1ドル \leq N, Q \leq 2 \times 10^5$
  • 1ドル \leq L_i < R_i \leq 2 \times N$
  • All questions are different from one another.

서브태스크

Subtasks Points Required subtasks $N$ $Q$ Other constraints
2 5 $≤ 4$ $= 1$ $L_1=1, R_1=2 \times N$
3 10 1 $\leq 100$ $= 1$ $L_1=1, R_1=2 \times N$
4 10 1, 2 $\leq 1000$ $= 1$ $L_1=1, R_1=2 \times N$
5 15 1, 2, 3 $\leq 2 \times 10^5$ $=1$ $L_1=1, R_1=2 \times N$
6 15 $\leq 2 \times 10^5$ $\leq 2 \times 10^5$ Special scoring.*
7 45 1, 2, 3, 4, 5 $\leq 2 \times 10^5$ $\leq 2 \times 10^5$

* Only in the sixth subtask, one test is considered to be successfully passed by your solution, if you have found correctly all answers that are 0ドル$. For the other questions in the test (for which the correct answers is not 0ドル$), it is only needed that the printed number is a integer in the interval $[1, 10^{18}]$.

예제 입력 1

3 1 1
)())((
1 6

예제 출력 1

1

예제 입력 2

5 10 1
()))(()(()
2 9
6 7
1 10
3 8
7 10
3 10
9 10
4 7
4 5
3 6

예제 출력 2

2
0
1
1
1
1
0
1
1
1

힌트

출처

Olympiad > International Autumn Tournament in Informatics > 2024 > Junior 4번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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