Grid Query 2
Time limit15sMemory limit1024 MB
Process up to 250,000 online queries on a 10^5 by 10^5 grid: add V to a rectangle, or return the rectangle's sum modulo 10^9+7, with each query decoded using the last printed answer.
- Level
Hard8 of 10
- Topics
- Segment tree, Math, Implementation
- Solved
- No attempts yet
Problem
The array has rows and columns, and every value starts at 0. Row numbers increase downward and column numbers increase to the right. The cell in row and column is written as .
Lawali wants to run operations of the following two types, just so you can suffer more watching the results.
- : Add to the value of every cell between and . ()
- : Compute the sum of the values of every cell between and and print it.
Input
The first line contains . ()
Each of the next lines contains five integers . ()
last_ans is 0 at the start, and it holds the most recently printed value. The parameters of the -th query are computed as follows.
, , , ,
are the of the -th query. They satisfy , , , and .
There are at most 50000 type 1 queries, and at least one type 2 query.
Output
For each type 2 query, print the sum modulo on its own line.