luogu#P8884. 「JEOI-R1」棋
「JEOI-R1」棋
Background
| Problem Setter | Reference Solution | Testdata | Validator | Tutorial |
|---|---|---|---|---|
| RedNebula | RedNebula and gyyyyx | gyyyyx | RedNebula | |
RedNebula and JF are playing a game of chess, and then...
Problem Description
There is now an chessboard. From top to bottom are rows , and from left to right are columns . A cell in row and column is labeled . There are chess pieces placed on some cells of the board, with no overlaps. A piece at can move to , , , (if these cells exist and have no piece on them).
There are several queries. Each query gives , and then gives positions, meaning a submatrix whose top-left corner is and bottom-right corner is . Ask whether it is possible to move pieces (with no limit on the number of moves) so that exactly the given positions inside the submatrix contain pieces. Queries are independent of each other.
To reduce constant factors in time complexity, it is recommended to use faster input methods.
Input Format
The first line contains three positive integers , representing the number of columns of the board, the number of rows of the board, and the number of existing pieces.
The next lines each contain two integers , indicating that there is a piece at row and column .
The next line contains one positive integer .
Then follow queries. For each query, the first line contains five positive integers . The next lines each contain two positive integers , indicating the positions where you want pieces to be inside the submatrix.
Output Format
For each query, if it is possible to move pieces (with no limit on the number of moves) so that inside the submatrix there are pieces at exactly the given positions, output YES; otherwise output NO.
3 3 5
1 2
1 3
2 1
3 2
3 3
3
1 2 2 3 0
1 2 3 3 4
1 2
1 3
2 3
3 3
1 1 2 3 2
1 3
2 2
NO
YES
NO
Hint
[Sample Explanation #1]
In the explanation, 0 represents an empty cell, and 1 represents a cell with a piece.
Initial state:
011
100
011
For the first query, it can be proven that the piece at cannot be moved out of the submatrix from to .
For the second query, consider moving the piece at to , obtaining:
011
101
001
This meets the query requirement. The moving method is not unique.
For the third query, it can be proven that the piece at cannot be moved out of the submatrix from to .
[Constraints]
For of the testdata, , and .
For another of the testdata, it is guaranteed that , and .
For another of the testdata, it is guaranteed that .
For of the testdata, , , , , , . For each query, , , .
[Hints and Notes]
Here is a relatively fast way to read a non-negative integer of type int. Calling read() returns a non-negative integer from the input, and at the same time reads the next character after it.
int read() {
int x(0);
char c(getchar());
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return x;
}
Translated by ChatGPT 5