#P11692. Cross Divine Name's Programs
Cross Divine Name's Programs
Cross Divine Name's Programs
There are programs in the computer of Cross Divine Name. Each program takes an integer as input and outputs an integer. The -th program is defined by four parameters , , , and (with and all values are integers). The function of the -th program is given by:
$$ f_i(x)=\begin{cases} (x-d_i)\bmod a_i & \text{if } x\in [l_i,r_i]\\ x & \text{if } x\notin [l_i,r_i]\\ \end{cases} $$Additionally, the computer maintains a checksum (an integer) which is initially . When the -th program is called with input , if and (i.e. both the subtraction and the modulo operation "take effect"), then the program updates the checksum by performing a bitwise XOR with .
Now, you are given an initial value stored in a variable and you reset the checksum to . Then, for a given query with indices and , you call the programs sequentially from to . That is, for each from to , update
Your task is to report the final checksum after the sequence of operations.
Note: The queries are given in an online manner. That is, you must process each query sequentially (compute the answer for the previous query before reading the next one).
inputFormat
The first line contains two integers and , representing the number of programs and the number of queries.
The next lines each contain four integers: , , , and , describing the -th program. It is guaranteed that and .
Then lines follow. Each query is given by three integers: , , and , where is the initial value of variable , and the programs from index to (inclusive) are executed sequentially.
outputFormat
For each query, output a single integer on a new line, which is the final checksum after processing the specified range of programs.
sample
3 2
1 10 1 2
2 20 2 3
5 15 1 4
5 1 3
10 2 3
2
3
</p>