#P8743. [蓝桥杯 2021 省 A] 异或数列

[蓝桥杯 2021 省 A] 异或数列

Problem Description

Alice and Bob are playing a game with an XOR sequence. At the beginning, Alice and Bob each have an integer aa and bb with initial value 00, and they share a given sequence X1,X2,,XnX_{1}, X_{2}, \cdots, X_{n} of length nn.

Alice and Bob take turns to make moves, with Alice moving first. In each move, one of the following two options can be chosen:

Option 1: Choose an XiX_{i} from the sequence and XOR it to Alice's number, i.e., change aa to aXia \oplus X_{i}. (Here \oplus denotes bitwise XOR.)

Option 2: Choose an XiX_{i} from the sequence and XOR it to Bob's number, i.e., change bb to bXib \oplus X_{i}.

Each number XiX_{i} can only be used once. When all XiX_{i} have been used (after nn rounds), the game ends. At the end of the game, the player with the larger number wins. If both numbers are equal, the game is a draw.

Now assume both players are smart enough and both use optimal strategies. Determine who will win.

Input Format

Each test file contains multiple queries. The queries are independent.

The first line contains an integer TT, which is the number of queries.

The next TT lines each contain one query. In the ii-th line, the first integer nin_{i} is the length of the sequence, followed by nin_{i} integers X1,X2,,XniX_{1}, X_{2}, \cdots, X_{n_{i}}, which are the numbers in the sequence.

Output Format

Output TT lines, each corresponding to the answer for one query.

Each line contains an integer 11, 00, or 1-1, meaning that Alice wins, the game is a draw, or Alice loses, respectively.

4
1 1
1 0
2 2 1
7 992438 1006399 781139 985280 4729 872779 563580
1
0
1
1

Hint

For all test cases, 1T2×1051 \leq T \leq 2\times 10^5, $1 \leq \sum\limits_{i=1}^{T} n_{i} \leq 2\times10^5$, 0Xi<2200 \leq X_{i}<2^{20}.

Lanqiao Cup 2021, Round 1, Provincial Contest, Group A, Problem G.

Translated by ChatGPT 5