Farmer Juan is a barista
InterviewTime limit2sMemory limit512 MB
Maintain a grid under range-add rectangle updates and point queries, answering each point query using only earlier updates.
- Level
Medium6 of 10
- Topics
- Prefix sum, Matrix, Implementation, Array
- Solved
- No attempts yet
Problem
Juan is a barista and he also runs a coffee farm. The farm is an grid, the coordinate runs from to , and the coordinate runs from to . Juan performs operations in the order they are given, and each operation is one of these two.
- Plant seeds: plant one seed of nutrition on every cell whose coordinate lies in and whose coordinate lies in .
- Check nutrition: report the sum of the nutrition of the seeds planted on cell .
A check reflects only the planting operations that come before it. A cell with no seed yet answers . Write the program that manages Juan's farm.
Input
The first line contains , , and . (, )
Each of the next lines contains one operation.
If the first number on the line is , the operation plants seeds and five numbers , , , , follow. (, , )
If the first number on the line is , the operation checks nutrition and two numbers and follow. (, )
Output
For every check operation, print its result on its own line, in the order the operations are given.