#K75992. Warehouse Grid Operations
Warehouse Grid Operations
Warehouse Grid Operations
You are given a warehouse represented by a 2D grid with n rows and m columns. Initially, all the storage units in the grid are empty (contain 0 items). You need to process a series of operations on the grid. There are two types of operations:
- Update Operation: Given by "1 x y q", update the storage unit at row x and column y to have exactly q items. Note that this operation sets the quantity rather than adding to it.
- Query Operation: Given by "2 x1 y1 x2 y2", compute the total number of items in the rectangular region from the top-left corner (x1, y1) to the bottom-right corner (x2, y2). Mathematically, if we denote the number of items at cell (i, j) by \(a_{ij}\), then the query asks you to compute:</p>
$$ S = \sum_{i=x_1}^{x_2} \sum_{j=y_1}^{y_2} a_{ij} $$
Your task is to perform all the operations in order and for each query operation, output the answer on a new line.
inputFormat
The input is given via standard input (stdin). The first line contains three integers n, m, and t where n is the number of rows, m is the number of columns, and t is the number of operations. Each of the following t lines represents an operation in one of the following formats:
- Update Operation: 1 x y q
- Query Operation: 2 x1 y1 x2 y2
All indices are 1-based.
outputFormat
For each query operation, output the computed sum on a new line to standard output (stdout).
## sample4 5 6
1 1 1 10
1 3 2 15
1 4 5 20
2 1 1 4 5
1 2 3 5
2 1 1 4 5
45
50
</p>