#K2786. Grid Queries

    ID: 24814 Type: Default 1000ms 256MiB

Grid Queries

Grid Queries

Given an \( n \times m \) grid initially filled with zeros, you need to process a sequence of queries. There are two types of queries:

  1. Update Query: The query is of the format 1 x y v and it updates the value of the cell at row \( x \) and column \( y \) to \( v \).
  2. Sum Query: The query is of the format 2 x1 y1 x2 y2 and it asks for the sum of all values in the subrectangle defined by the upper left corner \( (x1, y1) \) and the lower right corner \( (x2, y2) \).

Rows and columns are 1-indexed. For every sum query, print the answer on a new line.

Note: If a cell is updated multiple times, only the most recent update is considered.

inputFormat

The first line contains three integers: \( n \), \( m \) and \( q \) where \( n \) is the number of rows, \( m \) is the number of columns, and \( q \) is the number of queries.

Each of the following \( q \) lines contains a query in one of the following formats:

  • 1 x y v for an update query.
  • 2 x1 y1 x2 y2 for a sum query.

outputFormat

For each sum query (queries beginning with 2), output the computed sum on a new line.

## sample
3 3 6
1 1 1 5
1 2 2 3
1 3 3 7
2 1 1 3 3
1 2 3 4
2 1 1 3 3
15

19

</p>