시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
4 초 | 512 MB | 5 | 4 | 3 | 100.000% |
Define a neighbouring pair of cells in a matrix as a pair of cells $(r_a, c_a)$ and $(r_b, c_b)$ such that:
Define a spiral matrix as a matrix which satisfies the following conditions:
Given is a matrix of size $n \times m$ consisting of distinct positive integers. We are also given $q$ queries. Each query defines a submatrix with corners $(r_1, c_1)$ and $(r_2, c_2)$. For each query, determine whether this submatrix is spiral.
The first line contains three integers $n$, $m$ and $q$ ($1 \le n, m \le 2000$, $1 \le q \le 10^6$), denoting the size of the matrix and the number of queries, respectively.
Each of the next $n$ lines contains $m$ integers. The $j$-th integer on the $i$-th of these lines denotes the element $a_{i, j}$ located in the $i$-th row and $j$-th column of the matrix ($1 \le a_{i, j} \le 10^9$). It is guaranteed that all elements are distinct.
Each of the next $q$ lines contains four integers $r_1$, $c_1$, $r_2$, $c_2$ ($1 \le r_1 \le r_2 \le n$, $1 \le c_1 \le c_2 \le m$), denoting the corners of a submatrix.
For each query, print the answer on a separate line. Print "YES
" if the submatrix is spiral, or "NO
" otherwise.
5 7 10 10 11 12 13 14 15 16 9 2 3 32 31 30 17 8 1 4 25 26 29 18 7 6 5 24 27 28 19 52 51 50 23 22 21 20 1 1 5 7 1 1 4 1 2 2 5 3 1 4 5 7 1 1 4 3 1 1 5 3 2 2 2 2 2 2 2 3 3 4 5 7 3 3 4 4
NO YES NO YES YES NO YES YES YES NO