题目描述
Problem Description
You and a monster will play the following game:
- Initially, there are several rectangles. The height or width of any rectangle is an integer.
- You and the monster take turns selecting one rectangle and dividing it equally in a direction you can cut. The height or width of the resulting rectangles must also be integers. Mathematically, when a rectangle of size $h_i \times w_i$ is present, for an integer $n (\ > 1)$ such that $n \ | \ h_i$, you can create $ n $ rectangles of size $h_i / n \times w_i$, or for an integer $n (\ > 1)$ such that $n \ | \ w_i$, you can create $ n $ rectangles of size $h_i \times w_i / n$.
The player who cannot make a move loses.
Regarding the directions you can cut: you can cut any rectangle horizontally, and you can cut some rectangles vertically. On the other hand, the opponent can cut any rectangle vertically, and can cut some rectangles horizontally.
Each rectangle and the directions it can be cut are represented by four numbers $a, b, h, w\ (a, b \in \{0, 1\}, h, w$ are positive integers $ ) $. The rectangle has a height of $ h $ and a width of $ w $.
- You can cut this rectangle vertically if and only if $ a = 1 $.
- The opponent can cut this rectangle horizontally if and only if $ b = 1 $.
Given the information of $ N $ rectangles and their cutting directions, answer the following $ Q $ queries:
- For the $ i $-th query, integers $ l_i, r_i $ are given such that $1 \leq l_i \leq r_i \leq N$. Determine which player wins when playing the game using the $ l_i $-th to $ r_i $-th rectangles.
Input Format
The input is given from the standard input in the following format:
$ N $ $ a_1 $ $ b_1 $ $ h_1 $ $ w_1 $ $ : $ $ a_N $ $ b_N $ $ h_N $ $ w_N $ $ Q $ $ l_1 $ $ r_1 $ $ : $ $ l_Q $ $ r_Q $
Output Format
For each of the $ Q $ queries, output Yes if you win, or No if the opponent wins, one per line.
Sample Input and Output
Sample Input #1
1
1 1 3 4
1
1 1
Sample Output #1
Yes
Sample Input #2
2
1 0 2 5
0 1 5 2
1
1 2
Sample Output #2
No
Sample Input #3
13
1 1 3 1
1 1 4 1
1 1 5 9
1 1 2 6
1 1 5 3
1 1 5 8
1 1 9 7
1 1 9 3
1 1 2 3
1 1 8 4
1 1 6 2
1 1 6 4
1 1 3 3
10
3 13
1 6
1 5
9 10
6 11
1 12
3 9
2 4
4 11
1 3
Sample Output #3
No
Yes
Yes
Yes
Yes
No
Yes
No
Yes
Yes
Sample Input #4
20
0 1 121 219
1 0 300 241
1 1 215 112
0 1 268 156
0 1 33 204
1 0 202 111
1 1 59 70
1 1 272 83
0 0 190 285
1 1 291 283
1 1 299 90
1 1 80 48
0 1 107 291
0 1 158 136
1 1 127 223
1 1 227 93
1 1 79 183
1 0 92 26
1 0 190 300
0 1 294 38
30
14 20
14 19
11 19
11 15
4 8
9 10
5 12
1 7
18 19
12 14
13 15
6 19
6 10
2 5
9 18
9 13
18 19
17 18
4 13
16 18
2 13
13 13
7 12
1 8
2 20
4 12
7 7
10 17
14 18
5 12
Sample Output #4
Yes
Yes
Yes
No
No
Yes
Yes
Yes
Yes
No
No
Yes
Yes
Yes
No
No
Yes
Yes
No
Yes
Yes
No
Yes
Yes
Yes
No
Yes
No
No
Yes
Notes/Hints
Constraints
- $1 \leq N \leq 10^5$
- $0 < h_i \leq 10^5, 0 < w_i \leq 10^5\ (i=1,2,\dots,N)$
- $a_i, b_i \in \{0,1\}\ (i=1,2,\dots,N)$
- $1 \leq Q \leq 10^5$
- $1 \leq l_i \leq r_i \leq N\ (i=1,2,\dots,Q)$
Partial Points
This problem has partial points:
- Correctly answering inputs where both players can cut in both directions horizontally and vertically will earn you $ 400 $ points.
Explanation
Sample Explanation 1
For example, if you initially divide the rectangle vertically into $ 2 $ equal parts, you can win by mirroring the opponent's moves. This case is included in the partial points.
Sample Explanation 2
If the opponent mirrors your moves, you lose. This case is not included in the partial points.
Sample Explanation 3
This case is included in the partial points.
Sample Explanation 4
This case is not included in the partial points.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分