Under construction

Still being built. Things may change

Grid Query 2

Time limit15sMemory limit1024 MB

Summary
Process up to 250,000 online queries on a 10^5 by 10^5 grid: add V to a rectangle, or return the rectangle's sum modulo 10^9+7, with each query decoded using the last printed answer.
Level

Hard8 of 10

Topics
Segment tree, Math, Implementation
Solved
No attempts yet

Problem

The array has 10510^5 rows and 10510^5 columns, and every value starts at 0. Row numbers increase downward and column numbers increase to the right. The cell in row ii and column jj is written as (i−1,j−1)(i-1,j-1).

Lawali wants to run QQ operations of the following two types, just so you can suffer more watching the results.

  1. X1X_1 Y1Y_1 X2X_2 Y2Y_2 VV: Add VV to the value of every cell between (X1,Y1)(X_1,Y_1) and (X2,Y2)(X_2,Y_2). (V>0V > 0)
  2. X1X_1 Y1Y_1 X2X_2 Y2Y_2 00: Compute the sum of the values of every cell between (X1,Y1)(X_1,Y_1) and (X2,Y2)(X_2,Y_2) and print it.

Input

The first line contains QQ. (1≤Q≤2.5×1051 \le Q \le 2.5 \times 10^5)

Each of the next QQ lines contains five integers Ai,Bi,Ci,Di,KiA_i, B_i, C_i, D_i, K_i. (0≤Ai,Bi,Ci,Di,Ki<2310 \le A_i, B_i, C_i, D_i, K_i < 2^{31})

last_ans is 0 at the start, and it holds the most recently printed value. The parameters of the ii-th query are computed as follows.

Xi1=(Ai⊕last_ans) mod 105X_{i1} = (A_i \oplus \text{last\_ans}) \bmod 10^5, Yi1=(Bi⊕last_ans) mod 105Y_{i1} = (B_i \oplus \text{last\_ans}) \bmod 10^5, Xi2=(Ci⊕last_ans) mod 105X_{i2} = (C_i \oplus \text{last\_ans}) \bmod 10^5, Yi2=(Di⊕last_ans) mod 105Y_{i2} = (D_i \oplus \text{last\_ans}) \bmod 10^5, Vi=(Ki⊕last_ans) mod (109+7)V_i = (K_i \oplus \text{last\_ans}) \bmod (10^9+7)

Xi1,Yi1,Xi2,Yi2X_{i1}, Y_{i1}, X_{i2}, Y_{i2} are the X1,Y1,X2,Y2X_1, Y_1, X_2, Y_2 of the ii-th query. They satisfy 0≤Xi1,Yi1,Xi2,Yi2<1050 \le X_{i1}, Y_{i1}, X_{i2}, Y_{i2} < 10^5, 0≤Vi<109+70 \le V_i < 10^9+7, Xi1≤Xi2X_{i1} \le X_{i2}, and Yi1≤Yi2Y_{i1} \le Y_{i2}.

There are at most 50000 type 1 queries, and at least one type 2 query.

Output

For each type 2 query, print the sum modulo 109+710^9+7 on its own line.

Examples1

  1. Example 1

    Input
    10
    40 31 99 46 987780775
    38 0 68 74 0
    330276393 330276413 330276477 330276459 822003462
    330276378 330276364 330276464 330276479 306736652
    330276394 330276452 330276459 330276424 496257100
    330276368 330276474 330276459 330276474 520765327
    330276412 330276411 330276372 330276460 330276394
    969279116 969279132 969279133 969279209 969279141
    80818941 80818932 80818860 80818880 555081578
    80818880 80818869 80818848 80818840 80818939
    
    Expected output
    330276394
    969279141
    80818939
    775484641