#C5183. Maximum in Subgrid
Maximum in Subgrid
Maximum in Subgrid
You are given a grid of integers with n rows and m columns. You will also be provided with q queries. Each query specifies a subgrid of the original grid using four integers r1, c1, r2, c2 representing the top‐left and bottom‐right corners respectively (using 1-indexed coordinates). For each query, your task is to determine the maximum value within the subgrid.
The subgrid can be mathematically described as:
$$\{grid[i][j] \mid r_1 \leq i \leq r_2,\; c_1 \leq j \leq c_2\} $$Print the maximum for each query on a new line.
inputFormat
The input is given from standard input (stdin) with the following format:
- The first line contains two integers
n
andm
, denoting the number of rows and columns in the grid. - The next
n
lines each containm
integers, representing the rows of the grid. - The next line contains an integer
q
, the number of queries. - Each of the following
q
lines contains four integersr1
,c1
,r2
,c2
specifying a subgrid.
All indices use 1-based indexing.
outputFormat
For each query, output a single line with the maximum integer present in the specified subgrid.
## sample3 3
1 2 3
4 5 6
7 8 9
1
1 1 2 2
5
</p>