luogu#P9844. [ICPC2021 Nanjing R] Paimon Segment Tree

[ICPC2021 Nanjing R] Paimon Segment Tree

题目描述

Paimon just learns the persistent segment tree and decides to practice immediately. Therefore, Lumine gives her an easy problem to start:

Given a sequence a1,a2,,ana_1, a_2, \cdots, a_n of length nn, Lumine will apply mm modifications to the sequence. In the ii-th modification, indicated by three integers lil_i, rir_i (1lirin1 \le l_i \le r_i \le n) and xix_i, Lumine will change aka_k to (ak+xi)(a_k + x_i) for all likril_i \le k \le r_i.

Let ai,ta_{i, t} be the value of aia_i just after the tt-th operation. This way we can keep track of all historial versions of aia_i. Note that ai,ta_{i,t} might be the same as ai,t1a_{i,t-1} if it hasn't been modified in the tt-th modification. For completeness we also define ai,0a_{i, 0} as the initial value of aia_i.

After all modifications have been applied, Lumine will give Paimon qq queries about the sum of squares among the historical values. The kk-th query is indicated by four integers lkl_k, rkr_k, xkx_k and yky_k and requires Paimon to calculate

$$\sum\limits_{i=l_k}^{r_k}\sum\limits_{j=x_k}^{y_k} a_{i, j}^2 $$

Please help Paimon compute the result for all queries. As the answer might be very large, please output the answer modulo 109+710^9 + 7.

输入格式

There is only one test case in each test file.

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

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

For the following mm lines, the ii-th line contains three integers lil_i, rir_i and xix_i (1lirin1 \le l_i \le r_i \le n, xi<109+7|x_i| < 10^9 + 7) indicating the ii-th modification.

For the following qq lines, the ii-th line contains four integers lil_i, rir_i, xix_i and yiy_i (1lirin1 \le l_i \le r_i \le n, 0xiyim0 \le x_i \le y_i \le m) indicating the ii-th query.

输出格式

For each query output one line containing one integer indicating the answer modulo 109+710^9 + 7.

题目大意

题目描述

派蒙刚刚学习了可持久化线段树,她想马上练习一下。因此,荧决定给她出一道简单的问题:

给定数列a1,a2,,ana_1, a_2, \cdots, a_n,并进行mm次操作。操作包含3个参数lil_i, rir_i (1lirin1 \le l_i \le r_i \le n) 和 xix_i,代表对该序列第lil_i到第rir_i个元素加上xix_i

ai,ta_{i, t}tt次操作后aia_i的值。注意若aia_i未被修改,则ai,ta_{i,t}的值与ai,t1a_{i,t-1}相同。定义ai,0a_{i, 0}aia_i的初始值。

完成所有操作后,荧进行qq次询问,询问包含4个整数lkl_k, rkr_k, xkx_k and yky_k,派蒙需要回答

$$\sum\limits_{i=l_k}^{r_k}\sum\limits_{j=x_k}^{y_k} a_{i, j}^2 $$

请将答案对109+710^9 + 7取模后输出。

输入格式

每个测试点含一组测试数据。

第一行3个整数nn,mm,qq (1n,m,q5×1041 \le n, m, q \le 5 \times 10^4) 分别表示数列的长度,操作的次数和询问的次数。

第2行nn个整数 a1,a2,,ana_1, a_2, \cdots, a_n (ai<109+7|a_i| < 10^9 + 7) ,表示原始数列。

接下来mm行每行3个整数 lil_i, rir_i xix_i (1lirin1 \le l_i \le r_i \le n, xi<109+7|x_i| < 10^9 + 7),表示区间加操作。

接下来qq行每行包含四个整数 lil_i, rir_i, xix_i yiy_i (1lirin1 \le l_i \le r_i \le n, 0xiyim0 \le x_i \le y_i \le m),表示询问。

输出格式

对每个询问单起一行输出答案模109+710^9 + 7的结果。

3 1 1
8 1 6
2 3 2
2 2 0 0

1

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

180
825
8