#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 of length , Lumine will apply modifications to the sequence. In the -th modification, indicated by three integers , () and , Lumine will change to for all .
Let be the value of just after the -th operation. This way we can keep track of all historial versions of . Note that might be the same as if it hasn't been modified in the -th modification. For completeness we also define as the initial value of .
After all modifications have been applied, Lumine will give Paimon queries about the sum of squares among the historical values. The -th query is indicated by four integers , , and 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 .
输入格式
There is only one test case in each test file.
The first line of the input contains three integers , and () indicating the length of the sequence, the number of modifications and the number of queries.
The second line contains integers () indicating the initial sequence.
For the following lines, the -th line contains three integers , and (, ) indicating the -th modification.
For the following lines, the -th line contains four integers , , and (, ) indicating the -th query.
输出格式
For each query output one line containing one integer indicating the answer modulo .
题目大意
题目描述
派蒙刚刚学习了可持久化线段树,她想马上练习一下。因此,荧决定给她出一道简单的问题:
给定数列,并进行次操作。操作包含3个参数, () 和 ,代表对该序列第到第个元素加上。
记为次操作后的值。注意若未被修改,则的值与相同。定义是的初始值。
完成所有操作后,荧进行次询问,询问包含4个整数, , and ,派蒙需要回答
$$\sum\limits_{i=l_k}^{r_k}\sum\limits_{j=x_k}^{y_k} a_{i, j}^2 $$请将答案对取模后输出。
输入格式
每个测试点含一组测试数据。
第一行3个整数,, () 分别表示数列的长度,操作的次数和询问的次数。
第2行个整数 () ,表示原始数列。
接下来行每行3个整数 , (, ),表示区间加操作。
接下来行每行包含四个整数 , , (, ),表示询问。
输出格式
对每个询问单起一行输出答案模的结果。
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