#P97. [NOI 2025 Day 2] 三目运算符
[NOI 2025 Day 2] 三目运算符
Person in Charge
Problem Description
For a binary string of length , define the transformation as follows:
$$t_i = \begin{cases} s_i, & i \le 2, \\ s_i, & i \ge 3 \text{ and } s_{i-2} = 0, \\ s_{i-1}, & i \ge 3 \text{ and } s_{i-2} = 1. \end{cases}$$A fixed point of the transformation is defined as follows: if a binary string satisfies , then is called a fixed point of .
Let denote the string obtained by applying the transformation times to . Specifically, let . Find the smallest natural number such that is a fixed point of , i.e., the smallest natural number satisfying . It can be proven that such a always exists.
Little Z found this problem too simple, so he added modification operations. The -th () modification is given by two positive integers (), which flips all bits in the interval (i.e., 0 becomes 1 and 1 becomes 0). For the initial string and after each modification, you need to find the smallest natural number such that is a fixed point of .
Input Format
This problem contains multiple test cases.
The first line of input contains two non-negative integers , representing the test case number and the number of test cases, respectively. indicates that this test case is a sample.
For each test case:
The first line contains two positive integers , representing the length of and the number of modifications, respectively.
The second line contains a binary string of length , representing the initial string.
The -th line () contains two positive integers , representing a modification operation.
Output Format
For each test case, let be the answer for the initial string and () be the answer after the -th modification. Output a single positive integer, which is , where denotes the bitwise XOR operation.
Samples
0 2
5 2
11010
3 3
2 2
7 3
1010100
7 7
2 4
1 2
2
4
Sample 1 Explanation
This sample contains two test cases.
For the first test case:
- Initially, , , , , so ;
- After the first modification, , , so ;
- After the second modification, , , so .
Thus, the answer is $\bigoplus_{i=0}^{q} ((i+1) \times k_i) = (1 \times 3) \oplus (2 \times 1) \oplus (3 \times 1) = 3 \oplus 2 \oplus 3 = 2$.
For the second test case:
- Initially, , ;
- After the first modification, , ;
- After the second modification, , ;
- After the third modification, , .
Thus, the answer is $\bigoplus_{i=0}^{q} ((i+1) \times k_i) = (1 \times 1) \oplus (2 \times 1) \oplus (3 \times 5) \oplus (4 \times 2) = 4$.
Sample 2
See the files ternary/ternary2.in and ternary/ternary2.ans in the contestant directory.
This sample satisfies the constraints of test cases .
Sample 3
See the files ternary/ternary3.in and ternary/ternary3.ans in the contestant directory.
This sample satisfies the constraints of test cases .
Sample 4
See the files ternary/ternary4.in and ternary/ternary4.ans in the contestant directory.
This sample satisfies the constraints of test cases .
Sample 5
See the files ternary/ternary5.in and ternary/ternary5.ans in the contestant directory.
This sample satisfies the constraints of test cases .
Data Range
Let be the sums of across all test cases in a single test point. For all test cases, it is guaranteed:
- ;
- , ;
- , ;
- For all , ;
- For all , .
| Test Case | Special Properties | ||
|---|---|---|---|
| A | |||
| None | |||
| A | |||
| None | |||
| A | |||
| B | |||
| None | |||
| C | |||
| None |
- Special Property A: The initial string and each modified string have a position such that and .
- Special Property B: For all , and .
- Special Property C: For all , and .