Олимпиадный тренинг

Задача 29651. Maximum per matrix


Задача

Темы: sqrt декомпозиция
Given a matrix a of size \(n \cdot n\) (\(1 <= n <= 1000\), \(1 <= a_i <= 10^9\)). Also given are m (\(1 <= m <= 1000\)) queries of the form x1< /sub>, y1, x2, y2 (\(1 <= x_1 <= n\), \(1 <= y_1 <= n\), \(x_1 <= x_2 <= n\), \(y_1 <= y_2 <= n\)).
For each query, output the maximum element in the submatrix with edge coordinates x1, y1 and x2, y< sub>2.

 

Examples
# Input Output
1
4
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7
1
1 1 3 4
6