#P10012. [集训队互测 2023] 落日珊瑚
[集训队互测 2023] 落日珊瑚
Problem Description
You are given a bracket string of length consisting of square brackets and parentheses. A string is defined to be valid if and only if it satisfies one of the following:
- is an empty string.
- and is valid.
- and is valid.
- and both and are valid.
For example, () and [()] are valid bracket strings, but [()]()) is not.
Define an operation as follows: choose an interval , and for every character in the interval, change square brackets to parentheses, and change parentheses to square brackets.
Define the value of a bracket string as: if this string can be turned into a valid string using operations, then is the minimum number of operations needed; otherwise, it is .
You are given update/query operations of two types:
- Update: given an interval , change every character in the interval from square brackets to parentheses, and from parentheses to square brackets.
- Query: given an interval , compute .
Input Format
The first line contains four integers , representing the string length, the number of operations, the parameter for forcing online processing, and the subtask ID.
The next line contains a string of length .
Then follow lines, each containing three numbers , representing one operation.
Online is enforced. The actual $l = \min((L + T \cdot lastans) \bmod n + 1, (R + T \cdot lastans) \bmod n + 1)$ and $r = \max((L + T \cdot lastans) \bmod n + 1, (R + T \cdot lastans) \bmod n + 1)$, where is the answer to the previous query; if there was no previous query, then it is .
Please note that even for offline subtasks, it is still possible that and .
Output Format
Output several lines. For each query, output one answer.
10 10 0 0
[)]]((()][
2 10 6
1 6 6
1 3 6
2 5 7
2 3 3
2 10 4
1 7 1
2 4 4
2 4 2
1 5 5
1
0
0
1
0
0
20 20 0 0
[)])[)[](()((]]([[)[
2 9 3
2 8 10
1 4 15
1 5 9
1 16 10
1 18 20
1 1 8
2 8 9
1 2 16
1 10 13
1 16 9
1 8 1
2 20 7
2 14 11
1 3 16
1 15 18
1 6 4
2 10 7
2 2 4
2 13 2
2
0
0
1
2
1
0
4
Hint
For all testdata, , , , and .
| Subtask ID | Special Property | Score | |
|---|---|---|---|
| 1 | E | 5 | |
| 2 | |||
| 3 | AE | ||
| 4 | BE | ||
| 5 | CDE | ||
| 6 | CE | 10 | |
| 7 | DE | ||
| 8 | E | ||
| 9 | None | 20 | |
| 10 | 25 |
Property A: At each position, each of the four bracket types has probability .
Property B: It is guaranteed that there are no updates.
Property C: It is guaranteed that each update is a single-point update.
Property D: It is guaranteed that for the query interval , can be turned into a valid string after some operations, and there does not exist another such that can be turned into a valid string after some operations.
Property E: It is guaranteed that , i.e., the problem can be solved offline.
Input Format
Output Format
Hint
Translated by ChatGPT 5