#C2678. Grid Maximum Queries

    ID: 46020 Type: Default 1000ms 256MiB

Grid Maximum Queries

Grid Maximum Queries

You are given a grid with n rows and m columns. Initially, each cell of the grid contains an integer value. You need to process a series of queries on this grid. The queries are of two types:

  • SET x y v: Update the cell at row x and column y to the new value v.
  • MAX x₁ y₁ x₂ y₂: Print the maximum value in the subgrid with the top-left corner at (x₁, y₁) and the bottom-right corner at (x₂, y₂). Formally, the answer for this query is given by $$\max_{x_1 \leq i \leq x_2,\; y_1 \leq j \leq y_2} \; grid[i][j].$$

For each query of type "MAX", output a single line with the computed maximum value. If the query is of type "SET", no output is produced.

inputFormat

The input is given in the following format:

  1. The first line contains two integers n and m, representing the number of rows and columns of the grid.
  2. The next n lines each contain m integers, representing the initial grid values.
  3. The following line contains an integer q, the number of queries.
  4. Then follow q lines, each containing a query in one of the two formats:
    • "SET x y v" to update the cell at row x and column y to value v.
    • "MAX x₁ y₁ x₂ y₂" to query the maximum value in the subgrid spanning from (x₁,y₁) to (x₂,y₂).

outputFormat

For each query of type "MAX", print a single line with the maximum value found in the specified subgrid. There should be no output for the "SET" queries.## sample

3 3
1 2 3
4 5 6
7 8 9
5
MAX 1 1 3 3
SET 2 2 10
MAX 1 1 3 3
MAX 2 2 3 3
SET 3 1 0
9

10 10

</p>