You are given a one-indexed string of brackets of length
- It is an empty string.
- It has the form of
, where is a balanced string. - It has the form
, where and are both balanced strings.
For example, ()(())
is balanced, but )()(()
is not. A subsequence of a string is a string obtained by deleting some (possibly zero) characters of the string. Please note that a subsequence does not have to be contiguous. You are to write a program that supports
- Output the length of the longest balanced subsequence of the substring from index
to inclusive. - Flip the bracket located at index
. (i.e. from(
to)
and vice versa)
Constraints
Subtask 1 [30%]
Subtask 2 [70%]
No additional constraints.
Input Specification
The first line of input will contain two integers
The second line will contain a string of length (
and )
.
Each of the next
Output Specification
For each type
Sample Input
10 7
()))(())((
1 5 8
1 3 6
1 1 10
2 10
1 9 10
2 3
1 1 10
Sample Output
4
0
6
2
10
Explanation
For the first type (())
is balanced.
For the second type
For the third type ()(())
goes from index
For the fourth type ()
is balanced after the update.
For the fifth type ()()(())()
is balanced after the second update.
Comments