Codeforces Round 1028 (Div. 1)
D
Gellyfish and Forget-Me-Not
Codeforces
2900
原题
← CE →
翻译中…

Gellyfish and Flower are playing a game.

翻译中…

The game consists of two arrays of $n$ integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_n$, along with a binary string $c_1c_2\ldots c_n$ of length $n$.

翻译中…

There is also an integer $x$ which is initialized to $0$.

翻译中…

The game consists of $n$ rounds. For $i = 1,2,\ldots,n$, the round proceeds as follows:

翻译中…
  1. If $c_i = \mathtt{0}$, Gellyfish will be the active player. Otherwise, if $c_i = \mathtt{1}$, Flower will be the active player.
  2. The active player will perform exactly one of the following operations:
  • Set $x:=x \oplus a_i$.
    • Set $x:=x \oplus b_i$.
翻译中…

Here, $\oplus$ denotes the bitwise XOR operation.

翻译中…

Gellyfish wants to minimize the final value of $ x $ after $ n $ rounds, while Flower wants to maximize it.

翻译中…

Find the final value of $ x $ after all $ n $ rounds if both players play optimally.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of rounds of the game.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \lt 2^{60}$).

翻译中…

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($0 \leq b_i \lt 2^{60}$).

翻译中…

The fourth line of each test case contains a binary string $c$ of length $n$.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the final value of $ x $ after all $ n $ rounds.

翻译中…

Note

翻译中…

In the first test case, there's only one round and Gellyfish is the active player of that round. Therefore, she will choose $a_1$, and the final value of $x$ is $0$.

翻译中…

In the second test case, Flower will be the active player in both rounds. She will choose $a_1$ and $b_2$, and the final value of $x$ is $a_1 \oplus b_2 = 15$. Flower may also choose $b_1$ and $a_2$ instead for the same result of $x=a_2 \oplus b_1 = 15$.

翻译中…

In the third test case, $a_1 = b_1$ so it doesn't matter what decision Gellyfish makes in the first round. In the second round:

翻译中…
  • If Flower chooses $a_2$, then $x$ will become $7$. Gellyfish will choose $b_3$ in the third round, so the final value of $x$ will be $4$.
  • Otherwise, Flower chooses $b_2$, then $x$ will become $4$. Gellyfish will choose $a_3$ in the third round, so the final value of $x$ will be $6$.
翻译中…

Flower wants to maximize the final value of $x$, so Flower will choose $b_2$ in the second round. Therefore, the final value of $x$ will be $6$.

翻译中…

样例

Input #1
5
1
0
2
0
2
12 2
13 3
11
3
6 1 2
6 2 3
010
4
1 12 7 2
4 14 4 2
0111
9
0 5 10 6 6 2 6 2 11
7 3 15 3 6 7 6 7 8
110010010
Output #1
0
15
6
11
5
InputCopy OutputCopy
题目信息
题号
2115D
时间限制
2 s
内存限制
1024 MB
标签
位运算
动态规划
博弈论
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。