luogu#P12073. [OOI 2025] Alice, Bob, and two arrays.
[OOI 2025] Alice, Bob, and two arrays.
题目描述
There is an array of length and an array of length . All numbers in the arrays are integers and lie in the range from 1 to . There is also an initially empty array .
Alice and Bob play the following game on these arrays: the players take turns, and on their turn, a player must append a number to the end of the array such that remains a subsequence of both and . The player who cannot make a move loses. Alice goes first.
They will play the game times. For the -th game, they will choose two numbers and (), then remove the first elements from array and the first elements from array , and then play the game on the resulting arrays. After each deletion operation and before the next one, the arrays and are restored to their initial state, meaning that the numbers deleted from the arrays in one game may not be deleted in subsequent games. Also, the array is cleared between games.
The guys have their quirks, so they always choose and in such a way that after the deletions, the remaining parts of arrays and start with the same value.
Alice really wants to win, so she asks you to determine for each game whether she can win, assuming both players play optimally.
Note that the arrays can be very long, so they are provided in a special format. Each array is given as a sequence of segments of equal numbers. Array consists of such segments, and array consists of such segments. Each segment is defined by its length and the number that occupies that segment.
输入格式
The first line contains six integers ($1 \le N, M \le 10^9, 1 \le n, m, k \le 1600, 1 \le q \le 10^6$) — the length of the first array, the number of segments in the first array, the length of the second array, the number of segments in the second array, the number limit, and the number of games, respectively.
The next lines contain two integers and () — the length of the segment and the number written in that segment. These numbers define array : the first numbers of array are equal to , the next numbers are equal to , ..., the last numbers are equal to .
The next lines contain two integers and () — the length of the segment and the number written in that segment. These numbers define array . The format is similar to array . It is guaranteed that $\sum l_i^a = N, \sum l_i^b = M, v_i^a \ne v_{i+1}^a$, and .
The next lines contain pairs of integers and () — descriptions of the games.
For each game , it is guaranteed that if we remove the first elements from and the first elements from , the remaining parts of the arrays will start with the same value.
输出格式
For each of the games, print "Yes" if Alice wins with optimal strategy, and "No" if Bob wins.
5 1 5 1 1 9
5 1
5 1
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
Yes
No
Yes
No
No
Yes
Yes
Yes
Yes
7 3 7 3 2 12
2 1
3 2
2 1
2 2
3 1
2 2
0 2
0 3
0 4
1 2
1 3
1 4
2 5
2 6
3 5
3 6
4 5
4 6
Yes
No
Yes
Yes
No
Yes
No
Yes
No
Yes
Yes
Yes
提示
Note
In the first example, the arrays look like this: and .
- In the first query, , so the game will be played on the arrays and . In this case, players can only append the number 1 to the array , so after 5 moves the game will end, and Bob will lose because he won't be able to make a move.
- In the second query, , so the game will be played on the arrays and . In this case, the game will end after 4 moves, and Alice will lose.
- In the last query, , so the game will be played on the arrays and . In this case, Bob will lose.
In the second example, , .
- In the first query, and , so the game will be played on the arrays and . If Alice appends the number 2 to the array , Bob will also append the number 2, and then no moves will be left, so Alice will lose. Therefore, Alice must first append the number 1 to . After this, for similar reasons, if Bob appends the number 2 to the array, he will lose. So, he is forced to append the number 1, and the array becomes . Then Alice again appends the number 1 to the array , and Bob has no more moves left, so Alice wins.
- In the second query, and , so the game will be played on the arrays and . Following the reasoning in the previous example, Alice cannot append the number 2 to the array , because then she will lose. But if Alice appends the number 1, then Bob will also append the number 1, and after that, Alice will lose for similar reasons. Therefore, Bob wins in this case.