| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 3 | 2 | 2 | 66.667% |
Ryan is interested in strings consisting only of ‘(' and ‘)'. Especially, he loves balanced strings. Any balanced strings can be constructed using the following rules:
()" is balanced.(', $T$, and ‘)' in this order is balanced.For example, “()()" and “(()())" are balanced strings. “)(", “)()(()" and “(" are not balanced strings.
We define Ryan's sadness for a string $T$ as the minimum number of operations required to make $T$ into a balanced string by doing the following operations in any order and any number of times.
)' to the beginning of $T$.(' to the end of $T$.Ryan has a string $S$ of length $N$ consisting only of ‘(' and ‘)'. Given $Q$ queries, process them in order. There are two kinds of queries with the following formats.
(', replace it with ‘)'. If it is ‘)', replace it with ‘('.The input consists of a single test case of the following format.
$N$ $Q$
$S$
$t_1$ $l_1$ $r_1$
$\vdots$
$t_Q$ $l_Q$ $r_Q$
The first line contains two integers $N$ and $Q$ ($2 ≤ N ≤ 150\,000$, $1 ≤ Q ≤ 150\,000$) separated by a space, which represent the length of the string $S$ and the number of queries. The following line contains the string $S$, which consists only of ‘(' and ‘)', and whose length is $N$. Each of the next $Q$ lines contains three integers $t_i$, $l_i$ and $r_i$($1 ≤ t_i ≤ 2$, $1 ≤ l_i ≤ r_i ≤ N$) separated by a space, which represent the $i$-th query. It is guaranteed that there is at least one query with $t_i = 2$.
For each query in the format “$2$ $l$ $r$", print the value of Ryan's sadness, followed by a newline.
6 6 ())()( 2 1 6 1 2 4 2 1 4 2 2 5 1 1 5 2 1 6
2 5 0 6
7 5 (((((() 2 1 7 1 1 7 2 1 7 2 3 3 2 2 6
20 26 2 20