#P11657. 「FAOI-R5」datealive
「FAOI-R5」datealive
Background

Problem Description
Given a sequence of length , where . Each element corresponds to a parenthesis: if , the parenthesis at this position is a left parenthesis; if , it is a right parenthesis.
Let denote whether the parenthesis sequence in the interval is valid. If the sequence formed by is a valid parenthesis sequence, then ; otherwise, .
Definition of a valid parenthesis sequence:
- The empty string is a valid parenthesis sequence.
- If
Ais a valid parenthesis sequence, then(A)is a valid parenthesis sequence. - If
AandBare valid parenthesis sequences, thenABis a valid parenthesis sequence.
You need to perform operations online, of two types:
1 l r: Query $\max\limits_{[l',r']\in[l,r]}\{(r'-l'+1)\cdot f(l',r')\}$, i.e., query the length of the longest valid parenthesis substring within .2 l r: For all , modify to , i.e., flip every parenthesis in one by one.
Input Format
The first line contains two positive integers , representing the sequence length and the number of operations.
The next line contains non-negative integers , representing the initial sequence.
The next lines each contain three positive integers , representing the operation type and the encrypted .
To enforce online processing, the data is encrypted and must be decrypted as follows: let be the answer to the previous query operation, or if there is none. Compute and . If , swap .
Here, are the three parameters of the operation. If , it means the 1 l r operation described above; if , it means the 2 l r operation described above.
Output Format
For each query, output one line with a non-negative integer representing the answer.
10 10
0 1 1 0 0 1 0 0 1 1
2 7 8
2 10 5
2 5 1
2 7 6
2 7 1
2 4 5
2 3 4
1 5 2
1 4 1
1 7 7
4
2
0
20 20
0 0 0 1 1 1 1 0 0 1 0 0 0 1 0 0 0 0 1 1
2 16 7
2 12 10
1 4 5
1 14 7
1 16 7
2 15 12
1 12 2
1 3 4
1 1 10
2 14 3
2 19 1
1 20 9
2 14 16
1 10 13
1 6 8
2 1 2
1 8 16
1 9 15
1 17 12
2 15 14
0
2
8
2
0
2
6
4
0
2
0
0
Hint
Sample 1 Explanation
The decrypted result is as follows:
10 10
0 1 1 0 0 1 0 0 1 1
2 8 9
2 1 6
2 2 6
2 7 8
2 2 8
2 5 6
2 4 5
1 3 6
1 6 9
1 10 10
After modifications, the parenthesis string becomes .
- For the first query, take the substring to get . The whole substring is a valid parenthesis sequence, so the answer is .
- For the second query, take the substring to get . The substring is the longest valid parenthesis substring within it, so the answer is .
- For the third query, take the substring to get . The valid parenthesis substring within this substring is the empty string, so the answer is .
Constraints and Notes
This problem uses bundled testdata.
| Subtask ID | Score | Special Property | ||
|---|---|---|---|---|
| × | ||||
| × | ||||
Special property: it is guaranteed that there are no modification operations.
For all testdata, , , , , and .
For this problem, except for Subtask #3, it is guaranteed that the operation type is generated randomly, i.e., each time a random number from is chosen (with probability for both and ) as .
A large sample is provided in the problem attachments.
Translated by ChatGPT 5