#P8765. [蓝桥杯 2021 国 AB] 翻转括号序列
[蓝桥杯 2021 国 AB] 翻转括号序列
Problem Description
Given a parentheses sequence of length , you need to support two types of operations:
-
Flip all parentheses in the interval (from the -th character to the -th character in the sequence). That is, left parentheses become right parentheses, and right parentheses become left parentheses.
-
Given as the left endpoint, find the of the longest valid parentheses sequence (i.e., find the maximum such that is a valid parentheses sequence).
Input Format
The first line contains two integers , representing the length of the parentheses sequence and the number of operations.
The second line contains the given parentheses sequence, which only consists of left parentheses and right parentheses.
The next lines each describe an operation. If the line is 1 L R, it means the first type of operation with interval ; if the line is 2 L, it means the second type of operation with left endpoint .
Output Format
For each operation of the second type, output one line with the corresponding . If no such exists, output .
7 5
((())()
2 3
2 2
1 3 5
2 3
2 1
4
7
0
0
Hint
For of the testdata, .
For of the testdata, .
For of the testdata, .
For all testdata, $1 \leq n \leq 10^{6}, 1 \leq m \leq 2 \times 10^{5}$.
Lanqiao Cup 2021 National Contest Group A Problem H (Group B Problem I).
Translated by ChatGPT 5