| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 0.3 초 | 1024 MB | 12 | 9 | 9 | 75.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:
(+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.
| 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}]$.
3 1 1 )())(( 1 6
1
5 10 1 ()))(()(() 2 9 6 7 1 10 3 8 7 10 3 10 9 10 4 7 4 5 3 6
2 0 1 1 1 1 0 1 1 1