Paimon Segment Tree
Time limit2sMemory limit1024 MB
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 of length . Lumine applies modifications to it. The -th modification is given by three integers , () and , and changes to for every with .
Let be the value of just after the -th modification, so every past version of is tracked this way. If the -th modification does not touch , then equals . For completeness, is the initial value of .
After all modifications, Lumine gives Paimon queries. The -th query is given by four integers , , , , and asks for
Compute the answer to every query. The answers can be very large, so print each one modulo .
Input
The first line has three integers , , (): the length of the sequence, the number of modifications, and the number of queries.
The second line has integers (), the initial sequence.
Each of the next lines has , , (, ), describing one modification.
Each of the next lines has , , , (, ), describing one query.
There is only one test case per input file.
Output
For each query, print the answer modulo on its own line.