Under construction

Still being built. Things may change

Paimon Segment Tree

Time limit2sMemory limit1024 MB

Summary
Given an array changed by m range additions, answer q queries for the sum of squared values over an index range and a version range, modulo 1e9+7.
Level

Hard9 of 10

Topics
Segment tree, Prefix sum, Math
Solved
No attempts yet

Problem

Paimon just learned the persistent segment tree and wants to practice right away. So Lumine gives her an easy problem to start with.

You are given a sequence a1,a2,⋯ ,ana_1, a_2, \cdots, a_n of length nn. Lumine applies mm modifications to it. The ii-th modification is given by three integers lil_i, rir_i (1≤li≤ri≤n1 \le l_i \le r_i \le n) and xix_i, and changes aka_k to ak+xia_k + x_i for every kk with li≤k≤ril_i \le k \le r_i.

Let ai,ta_{i,t} be the value of aia_i just after the tt-th modification, so every past version of aia_i is tracked this way. If the tt-th modification does not touch aia_i, then ai,ta_{i,t} equals ai,t−1a_{i,t-1}. For completeness, ai,0a_{i,0} is the initial value of aia_i.

After all modifications, Lumine gives Paimon qq queries. The kk-th query is given by four integers lkl_k, rkr_k, xkx_k, yky_k, and asks for

∑i=lkrk∑j=xkykai,j2\sum_{i=l_k}^{r_k}\sum_{j=x_k}^{y_k} a_{i,j}^2

Compute the answer to every query. The answers can be very large, so print each one modulo 109+710^9 + 7.

Input

The first line has three integers nn, mm, qq (1≤n,m,q≤5×1041 \le n, m, q \le 5 \times 10^4): the length of the sequence, the number of modifications, and the number of queries.

The second line has nn integers a1,a2,⋯ ,ana_1, a_2, \cdots, a_n (∣ai∣<109+7|a_i| < 10^9 + 7), the initial sequence.

Each of the next mm lines has lil_i, rir_i, xix_i (1≤li≤ri≤n1 \le l_i \le r_i \le n, ∣xi∣<109+7|x_i| < 10^9 + 7), describing one modification.

Each of the next qq lines has lkl_k, rkr_k, xkx_k, yky_k (1≤lk≤rk≤n1 \le l_k \le r_k \le n, 0≤xk≤yk≤m0 \le x_k \le y_k \le m), describing one query.

There is only one test case per input file.

Output

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

Examples2

  1. Example 1

    Input
    3 1 1
    8 1 6
    2 3 2
    2 2 0 0
    
    Expected output
    1
    
  2. Example 2

    Input
    4 3 3
    2 3 2 2
    1 1 6
    1 3 3
    1 3 6
    2 2 2 3
    1 4 1 3
    4 4 2 3
    
    Expected output
    180
    825
    8