#P10255. 一首诗

    ID: 11547 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>洛谷原创O2优化洛谷月赛根号分治

一首诗

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 nn words. For convenience, ZHY records the poem as an integer sequence of length nn: a1,a2,,ana_1,a_2,\dots,a_n. 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 a1,a2,,ana_1,a_2,\dots,a_n, 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 al,al+1,,ara_l,a_{l+1},\dots,a_r (lrl\leq r) is “beautiful” if and only if for all li<rl\leq i<r, we have aiai+1a_i\neq a_{i+1}.

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 bib_i be the number of beautiful lines of length ii. YHZ wants to know b1,b2,,bnb_1,b_2,\dots,b_n. But even the total number of all bb values is too large, so he only needs b1b2bnb_1\oplus b_2\oplus\dots\oplus b_n.

Before YHZ finishes excerpting, literary master ZHY tells YHZ that he will make QQ rounds of polishing. Specifically, in each round, ZHY chooses a segment [li,ri][l_i,r_i] and an integer xix_i, and for all lijril_i\leq j\leq r_i, he modifies the word aja_j to aj+xia_j+x_i. Studious YHZ wants to excerpt the poem after each polishing; that is, for the sequence a1,a2,,ana_1,a_2,\dots,a_n after each modification, he wants to know b1b2bnb_1\oplus b_2\oplus\dots\oplus b_n.

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 a1na_{1\sim n}, define bib_i as the number of intervals of length ii in aa such that any two adjacent numbers are different. There are qq operations. Each operation gives l,r,xl,r,x, meaning adding xx to all elements in alra_{l\sim r}. Please output b1b2bnb_1\oplus b_2\oplus \cdots \oplus b_n before the first operation and after each operation, where \oplus denotes bitwise XOR.

Input Format

The first line contains two positive integers n,qn,q.

The second line contains nn integers a1,a2,,ana_{1},a_{2},\cdots,a_{n}.

The next qq lines each contain three integers li,ri,xil_{i},r_{i},x_{i}, describing one operation.

Output Format

Output q+1q+1 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 [1,2,3,4][1,2,3,4]. We get b1=4,b2=3,b3=2,b4=1b_1=4,b_2=3,b_3=2,b_4=1, so the answer is 4321=44\oplus 3 \oplus 2\oplus 1=4.

After the first modification, the sequence is [2,3,3,4][2,3,3,4]. We get b1=4,b2=2,b3=0,b4=0b_1=4,b_2=2,b_3=0,b_4=0, so the answer is 4200=64\oplus 2 \oplus 0\oplus 0=6.

After the second modification, the sequence is [2,4,4,4][2,4,4,4]. We get b1=4,b2=1,b3=0,b4=0b_1=4,b_2=1,b_3=0,b_4=0, so the answer is 4100=54\oplus 1 \oplus 0\oplus 0=5.


Subtask ID nn qq Special Property Score
00 300\le 300 None 1515
11 5000\le 5000
22 2×105\le 2\times 10^5 Guaranteed that ai,xa_i,x are uniformly random within the value range 1010
33 5×104\le 5\times 10^4 None 3030
44 2×105\le 2\times 10^5 l=1,r=nl=1,r=n 55
55 None 2525

For all testdata, 1n,q2×1051 \le n,q \le 2\times 10^5, 1lrn1\le l \le r \le n, 0x,ai1090\le |x|,|a_i|\le 10^9.

Translated by ChatGPT 5