#C4366. Maximum Value in a Submatrix
Maximum Value in a Submatrix
Maximum Value in a Submatrix
You are given a matrix (A) of size (n \times m) and (q) queries. Each query consists of four integers (i_1, j_1, i_2, j_2) representing the top-left and bottom-right corners of a submatrix. The indices are 1-indexed. For each query, determine the maximum element within the specified submatrix.
For example, if (A = \begin{pmatrix}1 & 2 & 3\ 4 & 5 & 6\ 7 & 8 & 9\end{pmatrix}) and a query is ((1, 1, 2, 2)), then the submatrix is (\begin{pmatrix}1 & 2\ 4 & 5\end{pmatrix}) and the maximum value is (5).
inputFormat
The input is given via standard input (stdin) in the following format:
(n) (m)
(A_{11} A_{12} \ldots A_{1m})
(A_{21} A_{22} \ldots A_{2m})
(\vdots)
(A_{n1} A_{n2} \ldots A_{nm})
(q)
Then (q) queries follow, each in a separate line, containing four integers (i_1), (j_1), (i_2), (j_2).
outputFormat
Print the maximum value for each query on a single line, separated by a space, to the standard output (stdout).## sample
3 3
1 2 3
4 5 6
7 8 9
2
1 1 2 2
2 2 3 3
5 9