Time limit: 2s
Memory limit: 256MB
Input:
Output:
You are given a matrix with rows and columns. You will have to answer queries of the following type:
i1 j1 i2 j2
— in the submatrix whose top-left corner is and its bottom-right corner is , are all of the elements distinct?
Input
The first line of input contains two integers and () — the height, and width, of the matrix, respectively.
Each of the next lines of input contain integers () — the elements of the -th row of the given matrix.
The next line contains a single integer () — the number of queries.
Each of the following lines contain integers , , , (, ) — the submatrix's corner cells' coordinates.
Output
For each query, print YES
, if all of the elements of the given submatrix are distinct, or NO
, otherwise.
Example 1
stdin
2 2
2 1
3 2
9
1 1 1 1
1 2 1 2
2 1 2 1
2 2 2 2
1 1 1 2
2 1 2 2
1 1 2 1
1 2 2 2
1 1 2 2
stdout
YES
YES
YES
YES
YES
YES
YES
YES
NO
Example 2
stdin
4 6
1 4 7 1 2 3
2 5 8 6 5 4
3 6 9 7 8 9
1 2 3 4 5 6
10
1 1 3 3
1 4 3 6
1 1 4 6
1 2 4 3
2 1 3 4
4 1 4 6
1 4 4 4
2 5 4 5
2 1 2 6
4 6 4 6
stdout
YES
YES
NO
YES
NO
YES
YES
NO
NO
YES