OTHS Coding Competition 2 P4 - Magic Barrier

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 3.0s
Memory limit: 512M

Author:
Problem type

Frieren is analyzing a magic barrier, whose strength at specific points can be represented as a 2D grid, a, with N rows, M columns, and unique values. Specifically, the strength of the barrier on the rth row and cth column is ar,c. She asks you Q questions in the form of (k,r1,c1,r2,c2) and your task for each of them is to determine whether k exists in the inclusive rectangle formed by ar1,c1 and ar2,c2.

Note: Fast input is highly recommended for this problem. Also, Python users should submit with PyPy as it is significantly faster.

Constraints

All values of ar,c are unique.

1k,ar,c109

1r1r2N

1c1c2M

Subtask 1 [15%]

1N,M,Q10

Subtask 2 [85%]

1N,M1000

1Q2×105

Input Specification

The first line contains 3 integers, N, M, and Q.

The next N lines contain M integers each, representing the barrier strength ar,c.

The next Q lines contain 5 integers each, k,r1,c1,r2,c2.

Output Specification

For each question, output yes if the k for that question exists in the given rectangle and no otherwise.

Sample Input 1

Copy
3 3 3
1 7 11
10 5 9
4 3 2
10 1 1 1 2
3 2 2 3 3
100 2 2 3 3

Sample Output 1

Copy
no
yes
no

Explanation for Sample Output 1

The rectangle for the first question is shown in blue. 10 is not inside it.

The rectangle for the second question is shown in yellow. 3 is inside it.

The rectangle for the third question is shown in yellow. 100 is not inside it (it's not even in the grid).

Sample Input 2

Copy
2 3 2
1 2 3
4 5 6
1 1 1 1 1
1 2 2 2 3

Sample Output 2

Copy
yes
no

Comments

There are no comments at the moment.