#P3179. [HAOI2015] 数组游戏

[HAOI2015] 数组游戏

Description

There is an array of length nn. Two players, A and B, play the following game on it: initially, some cells in the array are white and some are black. The players take turns.

On each turn, the current player chooses a white cell with index xx. Then they choose an integer kk between 1nx1 \ldots \lfloor \dfrac{n}{x} \rfloor, and flip the colors of all cells with indices x,2×x,,k×xx, 2\times x, \ldots, k\times x. The player who cannot make a move loses.

Now A (the first player) has several queries. For each query, you are given an initial state of the array. You need to determine whether A has a winning strategy for that initial state.

Input Format

The first line contains an integer nn, the length of the array.

The second line contains an integer kk, the number of queries.

The next 2×k2\times k lines describe the queries, two lines per query.

In these two lines, the first line contains a positive integer ww, the number of white cells in the array. The second line contains ww integers between 11 and nn, inclusive, which are the indices of the white cells.

Output Format

For each query, output one line with a string: output Yes if the first player has a winning strategy, otherwise output No.

3
2
2
1 2
2
2 3
Yes
No

Hint

Explanation for Sample Input/Output 1

In the first query, A chooses index 11 and flips cells 1×11\times 1 and 2×12\times 1.

In the second query, no matter which index A chooses, they can flip only one cell. B can then flip the other cell.

Constraints

For 30%30\% of the testdata, n20n \leq 20.

For 50%50\% of the testdata, n106n \leq 10^6.

For 70%70\% of the testdata, n107n \leq 10^7.

For 100%100\% of the testdata, n109n \leq 10^9, k,w100k, w \leq 100, and no cell appears more than once within a single query.

Translated by ChatGPT 5