#K48347. Grid Queries

    ID: 28400 Type: Default 1000ms 256MiB

Grid Queries

Grid Queries

You are given a grid of size \(n \times m\) with initial integer values and \(q\) queries. There are two types of queries:

  • Query type 1: 1 x1 y1 x2 y2. Report the maximum value in the sub-grid defined by the top-left coordinate \((x1, y1)\) and bottom-right coordinate \((x2, y2)\). The coordinates are 1-indexed.
  • Query type 2: 2 x1 y1 x2 y2. Increment each element in the sub-grid defined by \((x1, y1)\) and \((x2, y2)\) by \(1\).

After processing all queries in the given order, output the result for each query of type 1 in the same order as they appear. Each result should be printed on a new line.

Note: The grid is updated immediately when a type 2 query is executed, so subsequent queries are affected by the previous updates.

inputFormat

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

The next \(n\) lines each contain \(m\) integers describing the grid.

The following \(q\) lines each contain five integers: \(tp, x1, y1, x2, y2\), where \(tp\) indicates the type of the query (1 or 2) and \((x1, y1)\) and \((x2, y2)\) are the coordinates defining the sub-grid.

outputFormat

For each query of type 1, output a single line containing the maximum value in the specified sub-grid, after taking into account any previous updates.

## sample
4 4 3
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
1 1 1 3 3
2 2 2 4 4
1 1 1 4 4
11

17

</p>