#P4514. Matrix Rectangle Update and Sum Query
Matrix Rectangle Update and Sum Query
Matrix Rectangle Update and Sum Query
In this problem, you are given an n × m matrix initialized with 0. You need to perform Q operations. There are two kinds of operations:
- Update Operation: The format is:
1 a b c d x
. For this operation, add integer x to every element in the submatrix defined by the top‐left corner (a, b) and bottom‐right corner (c, d) (inclusive). - Query Operation: The format is:
2 a b c d
. For this operation, output the sum of all elements in the submatrix defined by the top‐left corner (a, b) and bottom‐right corner (c, d).
The operations are given sequentially. It is guaranteed that during the computation, both the intermediate and final values will always fit in a 32‐bit signed integer. This problem is inspired by the seven minutes of divine creativity — with ideas coming one after another until the problem was complete.
Note: The indices of the matrix are 1-indexed.
inputFormat
The first line contains three integers n, m and Q, representing the dimensions of the matrix and the number of operations respectively.
Each of the following Q lines represents an operation. An update operation starts with 1 and is followed by five integers a, b, c, d, x. A query operation starts with 2 and is followed by four integers a, b, c, d.
outputFormat
For each query operation, output the sum of the specified submatrix on a separate line.
sample
3 3 4
1 1 1 2 2 5
2 1 1 3 3
1 2 2 3 3 2
2 2 2 3 3
20
13
</p>