#P10767. 「CROI · R2」在相思树下 II

「CROI · R2」在相思树下 II

Description

Fox demons organized a single-elimination tournament on Mount Tu. The ii-th participant has strength ii. 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 2n2^n 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 mm queries. For a bracket with fixed match rules (but unknown initial participant placement), determine whether the aa-th participant can advance to the bb-th round. Output Yes if possible, otherwise No. Notably, if a participant becomes the champion, they are considered to have advanced to the (n+1)(n+1)-th round.

The figure below shows an example bracket with fixed match rules but unknown participant placement. Matches marked with max\max follow Rule 1 (stronger wins), while those marked with min\min follow Rule 2 (weaker wins).

Input Format

The first line contains two integers nn and mm, as described.

The next nn lines describe the bracket rules:

  • The ii-th line contains 2i12^{i-1} integers representing the rules for matches in the (ni+1)(n-i+1)-th round (from left to right). Here, 1 denotes Rule 1, and 2 denotes Rule 2.

The next mm lines each contain two integers aa and bb, representing a query.

Output Format

Output mm 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 {1,2,3,4,7,8,5,6}\{1,2,3,4,7,8,5,6\}. 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): n3n \leq 3, m20m \leq 20.
  • Subtask 1 (10 points): For all queries, b2b \leq 2.
  • 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: 1a2n1 \leq a \leq 2^n, 1bn+11 \leq b \leq n+1, 12n,m1061 \leq 2^n, m \leq 10^6.