#C6972. Grid Query and Update Operations

    ID: 50791 Type: Default 1000ms 256MiB

Grid Query and Update Operations

Grid Query and Update Operations

You are given a grid with n rows and m columns, initially filled with zeroes. You need to perform two types of operations on the grid:

  • Add Operation: add x y k – adds the value \(k\) to the cell at position \((x,y)\).
  • Query Operation: query x1 y1 x2 y2 – calculates and returns the sum of all values in the subgrid defined by the top-left corner \((x_1,y_1)\) and the bottom-right corner \((x_2,y_2)\). The indices in the operations are 1-indexed.

Process the operations in the order they are given. For every query operation, output the resulting sum.

inputFormat

The first line contains two integers (n) and (m) representing the number of rows and columns respectively. The second line contains a single integer (q) representing the number of operations. Each of the next (q) lines contains an operation in one of the following formats:

  • add x y k
  • query x1 y1 x2 y2

It is guaranteed that all given indices are valid within the grid.

outputFormat

For each query operation, output a single line containing the sum of the specified subgrid.## sample

3 3
5
add 1 1 3
add 2 2 4
add 3 3 5
query 1 1 2 2
query 1 1 3 3
7

12

</p>