#P10513. 括号
括号
Problem Description
Yuan gives you a string of length . consists only of ( and ).
She will perform operations on it. There are two types of operations:
1 l r: She will flip the parentheses from to , i.e.,(becomes), and)becomes(.2 l r: She wants to know the value of the length of the longest valid parentheses subsequence in the interval , divided by .
Yuan considers the following parentheses sequences to be valid:
-
The empty sequence is a valid sequence.
-
If
Ais a valid sequence, then(A)is also a valid sequence. -
If
AandBare both valid sequences, thenABis also a valid sequence.
Yuan considers a subsequence of sequence to be a sequence that satisfies .
Since there are too many operations, she cannot compute them all. Please help her.
Input Format
The first line contains an integer .
The second line contains a string of length , guaranteed to consist only of ( and ).
The third line contains an integer .
The next lines each contain three numbers , , , corresponding to the two operations above.
Output Format
For each operation with , output one line containing an integer, representing the answer.
6
(()())
5
2 2 3
1 1 3
2 2 3
2 4 6
2 3 6
1
0
1
2
Hint
[Sample Explanation]
- The first extracted string is
(), and the answer is . - After flipping, the string becomes
))(()). - The second extracted string is
)(, and the answer is . - The third extracted string is
()), and the answer is . - The fourth extracted string is
(()), and the answer is .
[Constraints]
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
- Another of the testdata satisfies and is randomly generated.
- Another of the testdata satisfies , but the testdata is not guaranteed to be randomly generated.
For all testdata, it is guaranteed that , , , . The testdata has multiple levels.
Translated by ChatGPT 5