#P10255. 一首诗
一首诗
Background
A formal statement of the problem is given at the end of the description.
Problem Description
Literary master ZHY created a poem.
This poem consists of words. For convenience, ZHY records the poem as an integer sequence of length : . After finishing, ZHY immediately shared his work with YHZ. After appreciating the beauty of the poem, YHZ wants to improve his literary skills by excerpting lines from it.
YHZ believes that a “line” should be a continuous subsequence of , and the length of the line is the length of that subsequence. Of course, he will not excerpt all lines, but only chooses “beautiful lines” to excerpt. Since he does not understand grammar, YHZ simply thinks a line is “beautiful” if and only if there are no two adjacent repeated words in the line. Formally, a line formed by a continuous subsequence () is “beautiful” if and only if for all , we have .
YHZ finds that there are too many beautiful lines in ZHY’s poem, so he needs to classify them. Still because he does not understand grammar, he wants to classify them directly by line length. Let be the number of beautiful lines of length . YHZ wants to know . But even the total number of all values is too large, so he only needs .
Before YHZ finishes excerpting, literary master ZHY tells YHZ that he will make rounds of polishing. Specifically, in each round, ZHY chooses a segment and an integer , and for all , he modifies the word to . Studious YHZ wants to excerpt the poem after each polishing; that is, for the sequence after each modification, he wants to know .
However, ZHY is too hardworking and makes too many rounds of polishing, and YHZ cannot handle such a large workload. So he asks you to help him.
Formal statement:
Given a sequence , define as the number of intervals of length in such that any two adjacent numbers are different. There are operations. Each operation gives , meaning adding to all elements in . Please output before the first operation and after each operation, where denotes bitwise XOR.
Input Format
The first line contains two positive integers .
The second line contains integers .
The next lines each contain three integers , describing one operation.
Output Format
Output lines, representing the answer before the first operation and after each operation.
4 2
1 2 3 4
1 2 1
2 3 1
4
6
5
Hint
Explanation of the sample:
Before the first modification, the sequence is . We get , so the answer is .
After the first modification, the sequence is . We get , so the answer is .
After the second modification, the sequence is . We get , so the answer is .
| Subtask ID | Special Property | Score | ||
|---|---|---|---|---|
| None | ||||
| Guaranteed that are uniformly random within the value range | ||||
| None | ||||
| None | ||||
For all testdata, , , .
Translated by ChatGPT 5