#P5609. [Ynoi2013] 对数据结构的爱

[Ynoi2013] 对数据结构的爱

Problem Description

Nauuo is a girl who likes programming. One day she was working on a problem that asked her to compute the sum of some numbers modulo an integer pp.

She wrote the following code, but got WA.

She quickly found the bug: the ModAdd function only works for numbers in [0,p)[0,p), but in this problem the numbers may fall outside this range. She became curious about this incorrect function, so she wants to know what result it actually produces.

However, the original code runs too slowly, so she asks you for help.

Given an array a1,a2,,ana_1,a_2,\ldots,a_n and an integer pp, there are mm queries. Each query gives three integers ll, rr, and xx. You need to compute the return value of Sum(a,l,r,x,p). The definition of Sum has already been given in the pseudocode above.

Note that in the code above, integers will not overflow.

Input Format

The first line contains three integers nn, mm, pp, representing the length of the array, the number of queries, and the modulus. Note that the modulus is only used in ModAdd.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n, representing the given array.

The next mm lines each contain three integers ll, rr, and xx. You need to compute Sum(a,l,r,x,p).

This problem is forced online. All input l,r,xl,r,x must be XORed with lastanslastans, where lastanslastans is defined as (the answer of the previous query) modulo nn. If the answer is negative, you need to take the modulo to make it positive. If there has been no previous query, then it is 00.

Output Format

Output mm integers in order, one per line, representing the answers to the queries.

4 5 6
7 2 -3 17
2 3 1
1 3 3
0 3 0
2 4 2
4 4 0
0
-3
4
12
11

Hint

Idea: rushcheyo&nzhtl1477, Solution: ccz181078, Code: rushcheyo&ccz181078, Data: rushcheyo&nzhtl1477

Constraints: for 100%100\% of the testdata, 1n1061\le n\le10^6, 1m2×1051\le m\le2\times 10^5, 1p1091\le p\le10^9, 109ai109-10^9\le a_i\le10^9, 1lrn1\le l\le r\le n, 0xp10\le x\le p-1.

Translated by ChatGPT 5