Rectangle update and rectangle sum
Time limit1sMemory limit256 MB
You add w to all cells in one rectangle per update and print the cell sum of one rectangle per query in order.
- Level
Medium7 of 10
- Topics
- Segment tree, Prefix sum, Matrix
- Solved
- No attempts yet
Problem
You have an grid. Rows are numbered 1 to from bottom to top, columns are numbered 1 to from left to right, and every cell starts at 0. Cell is the cell where row meets column .
Process operations on the grid, in the order given.
1 a b x y w: add to every cell of the rectangle whose bottom left cell is and whose top right cell is .
2 a b x y: print the sum of every cell of the rectangle whose bottom left cell is and whose top right cell is .
Input
The first line holds , , and , separated by spaces. Each of the next lines holds one operation in the format above.
and . Every operation satisfies and , and in an operation of type 1 is an integer with .
Output
For each operation of type 2, print the sum on its own line, in input order. A sum can exceed the range of a 32-bit integer.