#P10767. 「CROI · R2」在相思树下 II
「CROI · R2」在相思树下 II
Description
Fox demons organized a single-elimination tournament on Mount Tu. The -th participant has strength . In each match, two contestants compete, and the winner advances to the next round. To allow both stronger and weaker participants a chance to win, YaYa designed a special set of rules.
Specifically, there are participants in the tournament. Each match follows one of two predetermined rules:
- Rule 1: The stronger participant wins.
- Rule 2: The weaker participant wins.
YaYa will ask you queries. For a bracket with fixed match rules (but unknown initial participant placement), determine whether the -th participant can advance to the -th round. Output Yes if possible, otherwise No. Notably, if a participant becomes the champion, they are considered to have advanced to the -th round.
The figure below shows an example bracket with fixed match rules but unknown participant placement. Matches marked with follow Rule 1 (stronger wins), while those marked with follow Rule 2 (weaker wins).

Input Format
The first line contains two integers and , as described.
The next lines describe the bracket rules:
- The -th line contains integers representing the rules for matches in the -th round (from left to right). Here,
1denotes Rule 1, and2denotes Rule 2.
The next lines each contain two integers and , representing a query.
Output Format
Output lines, each containing Yes or No as the answer to the corresponding query.
3 3
2
2 1
2 1 2 1
6 2
7 3
8 4
Yes
Yes
No
Hint
【Sample Explanation】
The sample bracket matches the figure in the problem description.
To allow the 6th participant to reach the second round, or the 7th participant to reach the third round, participants can be arranged as . The specific match outcomes are shown below:

It is impossible for the 8th participant to reach the 4th round (i.e., become champion).
【Data Range】
This problem uses bundled tests.
- Subtask 0 (20 points): , .
- Subtask 1 (10 points): For all queries, .
- Subtask 2 (10 points): All matches follow Rule 1.
- Subtask 3 (20 points): All matches in the same round follow the same rule.
- Subtask 4 (40 points): No additional constraints.
For all test cases: , , .
京公网安备 11011102002149号