#P17198. [KOI 2026 #2] 杂技
[KOI 2026 #2] 杂技
Problem Description
Alice and Bob, two acrobats, are preparing to perform on a balance beam. The balance beam consists of consecutive cells, numbered from to from left to right.
During the performance, at any moment, each acrobat must stand on exactly one cell. To ensure safety, at all times the index of the cell where Alice stands must be less than the index of the cell where Bob stands. That is, Alice must always stand to the left of Bob, and they cannot stand on the same cell.
There are springboards installed on the balance beam. The -th () springboard is installed on cell . After an acrobat standing on cell uses this springboard, they will land exactly on cell .
Multiple springboards may be installed on the same cell. Both acrobats may use any springboard any number of times.
A performance consists of executing any number of actions (possibly ). In one action, exactly one of the two acrobats performs one of the following two operations:
- Walk: Alice may move one cell to the right from her current cell; Bob may move one cell to the left from his current cell. Alice cannot walk left, and Bob cannot walk right.
- Jump: Choose and use a springboard installed on the cell where the acrobat is currently standing. That is, for some integer (), an acrobat standing on cell may use the -th springboard and land on cell .
After an action is performed, Alice must still stand on a cell to the left of Bob. Any action that would violate this condition cannot be performed.
The two acrobats have performance plans. The -th () performance plan is given by four integers satisfying and . The -th plan is called valid if, by performing some sequence of actions, starting from the state where Alice and Bob stand on cells and respectively, they can eventually end in the state where they stand on cells and respectively.
For each of the performance plans, determine whether it is valid.
Input Format
The first line contains two space-separated integers and .
The next lines give information about the springboards. Line () contains two space-separated integers and , describing the -th springboard.
The next line contains an integer , the number of performance plans.
The next lines describe the performance plans. Line () contains four space-separated integers , describing the -th performance plan.
Output Format
Output lines starting from the first line. Line () should be the answer to the -th performance plan: if it is possible to start with Alice and Bob standing on cells and respectively and eventually make them stand on cells and respectively, output YES; otherwise output NO.
6 2
3 5
4 2
4
2 4 3 4
2 3 2 5
2 3 4 5
3 4 1 2
YES
YES
YES
NO
10 3
5 10
6 8
7 4
5
5 6 4 10
5 6 3 9
1 10 2 9
6 8 4 9
9 10 1 10
YES
NO
YES
YES
NO
Hint
Explanation of Sample 1
In the second performance plan, Alice and Bob start on cells and respectively. Bob uses the springboard on cell to move to cell . Then Alice and Bob are on cells and respectively, reaching the target state.
In the fourth performance plan, when Alice and Bob are on cells and respectively, no action can be performed.
- If Alice walks right, both would stand on cell , violating the condition.
- If Bob walks left, both would stand on cell , violating the condition.
- If Bob uses the springboard on cell and lands on cell , he would stand to the left of Alice on cell , violating the condition.
Therefore, it is impossible to reach the target state where Alice and Bob stand on cells and respectively.
Constraints
- All given values are integers.
- .
- .
- .
- For each integer (), and .
- For each integer (), and .
Subtasks
- ( points) .
- ( points) For each integer (), .
- ( points) .
- ( points) .
- ( points) No additional constraints.
Translated by ChatGPT-5.6.
Translated by ChatGPT 5