#C7347. Grid Query Processing
Grid Query Processing
Grid Query Processing
You are given a grid of size \(N\times M\) filled with integers. You need to process \(Q\) queries. There are two types of queries:
- UPDATE r c x: Update the value of the cell at row \(r\) and column \(c\) to \(x\). (The grid is 1-indexed and the cell \(grid[r][c]\) is updated.)
- MAXIMUM r1 c1 r2 c2: Find the maximum value in the sub-grid defined by the top left cell \((r1, c1)\) and bottom right cell \((r2, c2)\).
For example, for a query 'MAXIMUM 1 1 2 3', you should output the maximum value in the subgrid from row 1 to 2 and column 1 to 3.
Note: Coordinates are based on 1-indexing.
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 representing the grid.
The following \(Q\) lines each contain a query in one of the two following formats:
UPDATE r c x
MAXIMUM r1 c1 r2 c2
outputFormat
For each MAXIMUM
query, output the maximum value in the specified sub-grid on a new line. UPDATE
queries produce no output.
4 4 5
5 1 3 7
9 3 4 2
8 6 7 1
2 3 5 6
UPDATE 2 2 10
MAXIMUM 1 1 2 3
UPDATE 3 4 12
MAXIMUM 3 1 4 4
MAXIMUM 1 1 4 4
10
12
12
</p>