#P11692. Cross Divine Name's Programs

    ID: 13782 Type: Default 1000ms 256MiB

Cross Divine Name's Programs

Cross Divine Name's Programs

There are nn programs in the computer of Cross Divine Name. Each program takes an integer as input and outputs an integer. The ii-th program is defined by four parameters lil_i, rir_i, did_i, and aia_i (with 0diliri0 \le d_i \le l_i \le r_i and all values are integers). The function of the ii-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 00. When the ii-th program is called with input xx, if x[li,ri]x \in [l_i, r_i] and xdiaix-d_i \ge a_i (i.e. both the subtraction and the modulo operation "take effect"), then the program updates the checksum by performing a bitwise XOR with aia_i.

Now, you are given an initial value xx stored in a variable v\mathbf{v} and you reset the checksum to 00. Then, for a given query with indices LL and RR, you call the programs sequentially from i=Li = L to RR. That is, for each ii from LL to RR, update

vfi(v).\mathbf{v} \gets f_i(\mathbf{v}).

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 nn and mm, representing the number of programs and the number of queries.

The next nn lines each contain four integers: lil_i, rir_i, did_i, and aia_i, describing the ii-th program. It is guaranteed that 0diliri0 \le d_i \le l_i \le r_i and ai>0a_i > 0.

Then mm lines follow. Each query is given by three integers: xx, LL, and RR, where xx is the initial value of variable v\mathbf{v}, and the programs from index LL to RR (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>