#P9844. [ICPC 2021 Nanjing R] Paimon Segment Tree
[ICPC 2021 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 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
