#P2574. XOR的艺术
XOR的艺术
Description
AKN thought the first problem was too easy and refused to write it, so he started a new game. In the game, he found a pattern in the damage calculation, as follows:
- There is a damage string, which is a string of length consisting only of the characters
0and1. The first character is considered the first position, i.e., indices start from . - Given a range , the damage is the number of characters
1within that range of the damage string. - The damage string can be modified by toggling all characters in : change every
0to1and every1to0.
AKN wants to know the damage at certain times. Please help him compute it.
Input Format
The first line contains two integers separated by a space, representing the length of the damage string and the number of operations .
The second line is a string of length , representing the damage string.
From the -rd to the -nd line, each line contains three integers , representing the type and interval of the -th operation. The rules are:
- If , toggle the characters in the interval of the damage string: change
0to1and1to0. - If , query how many characters
1are in the interval of the damage string.
Output Format
For each query, output a single line with one integer, representing the number of 1 in the interval.
10 6
1011101001
0 2 4
1 1 5
0 3 7
1 1 10
0 1 4
1 2 6
3
6
1
Hint
Explanation for Sample Input/Output 1:
The original damage string is 1011101001.
For the first operation, toggle the characters in , and the damage string becomes 1100101001.
For the second operation, query the number of 1 in , which is .
For the third operation, toggle the characters in , and the damage string becomes 1111010001.
For the fourth operation, query the number of 1 in , which is .
For the fifth operation, toggle the characters in , and the damage string becomes 0000010001.
For the sixth operation, query the number of 1 in , which is .
Constraints:
- For of the testdata, it is guaranteed that .
- For an additional of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that , , , and contains only the characters
0and1.
Translated by ChatGPT 5
京公网安备 11011102002149号