#K54717. Elevation Grid Queries
Elevation Grid Queries
Elevation Grid Queries
You are given a grid representing elevations. You will receive several queries on this grid. There are three types of queries:
U x y v
: Update the cell at rowx
and columny
to the valuev
.Min x1 y1 x2 y2
: Find the minimum elevation in the subgrid defined by the top-left cell(x1, y1)
and bottom-right cell(x2, y2)
.Max x1 y1 x2 y2
: Find the maximum elevation in the subgrid defined by the top-left cell(x1, y1)
and bottom-right cell(x2, y2)
.
The grid uses 1-indexing. For any subgrid query, the answer is computed using the formula: $$ answer = \min_{i=x_1}^{x_2} \min_{j=y_1}^{y_2} grid[i][j] \quad \text{or} \quad \max_{i=x_1}^{x_2} \max_{j=y_1}^{y_2} grid[i][j] $$ depending on whether it's a Min or Max query.
After processing all queries, output the result of each Min and Max query on a separate line.
inputFormat
The input is given via stdin in the following format:
n m row1 row2 ... (n rows each containing m integers) q query1 query2 ... (q queries, one per line)
Each query is in one of the three forms described above. Note that n
and m
are the grid dimensions.
outputFormat
For each Min
and Max
query, output the result on a separate line via stdout.
3 3
5 8 6
3 2 7
9 4 1
6
Min 1 1 2 2
Max 2 2 3 3
U 2 2 10
Min 1 1 2 2
Max 1 1 3 3
Min 2 2 3 3
2
7
3
10
1
</p>