CF2115D.Gellyfish and Forget-Me-Not

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Gellyfish and Flower are playing a game.

The game consists of two arrays of nn integers a1,a2,…,ana_1,a_2,\ldots,a_n and b1,b2,…,bnb_1,b_2,\ldots,b_n, along with a binary string c1c2…cnc_1c_2\ldots c_n of length nn.

There is also an integer xx which is initialized to 00.

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

  1. If ci=0c_i = \mathtt{0}, Gellyfish will be the active player. Otherwise, if ci=1c_i = \mathtt{1}, Flower will be the active player.
  2. The active player will perform exactly one of the following operations:
    • Set x:=x⊕aix:=x \oplus a_i.
    • Set x:=x⊕bix:=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.

水母和花朵正在玩一个游戏。

游戏包含两个长度为 nn 的整数数组 a1,a2,…,ana_1,a_2,\ldots,a_n 和 b1,b2,…,bnb_1,b_2,\ldots,b_n,以及一个长度为 nn 的二进制字符串 c1c2…cnc_1c_2\ldots c_n。

此外还有一个整数 xx,初始值为 00。

游戏共进行 nn 轮。对 i=1,2,…,ni = 1,2,\ldots,n,第 ii 轮按如下方式进行:

  1. 若 ci=0c_i = \mathtt{0},则水母为当前活跃玩家;若 ci=1c_i = \mathtt{1},则花朵为当前活跃玩家。
  2. 当前活跃玩家恰好执行以下操作之一:
    • 将 xx 更新为 x:=x⊕aix:=x \oplus a_i;
    • 将 xx 更新为 x:=x⊕bix:=x \oplus b_i。

其中,⊕\oplus 表示按位异或运算。

水母希望在 nn 轮结束后使 xx 的最终值尽可能小,而花朵希望使其尽可能大。

若双方均采取最优策略,求 nn 轮结束后 xx 的最终值。

输入格式

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

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

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai<2600 \leq a_i \lt 2^{60}).

The third line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (0≤bi<2600 \leq b_i \lt 2^{60}).

The fourth line of each test case contains a binary string cc of length nn.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)—— 表示游戏的轮数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai<2600 \leq a_i \lt 2^{60})。

每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(0≤bi<2600 \leq b_i \lt 2^{60})。

每个测试用例的第四行包含一个长度为 nn 的二进制字符串 cc。

保证所有测试用例的 nn 值之和不超过 10510^5。

输出格式

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

对于每个测试用例,输出一个整数——经过全部 $ n $ 轮操作后 $ x $ 的最终值。

输入输出样例

  • 输入#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

    输出#1

    0
    15
    6
    11
    5

说明/提示

In the first test case, there's only one round and Gellyfish is the active player of that round. Therefore, she will choose a1a_1, and the final value of xx is 00.

In the second test case, Flower will be the active player in both rounds. She will choose a1a_1 and b2b_2, and the final value of xx is a1⊕b2=15a_1 \oplus b_2 = 15. Flower may also choose b1b_1 and a2a_2 instead for the same result of x=a2⊕b1=15x=a_2 \oplus b_1 = 15.

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

  • If Flower chooses a2a_2, then xx will become 77. Gellyfish will choose b3b_3 in the third round, so the final value of xx will be 44.
  • Otherwise, Flower chooses b2b_2, then xx will become 44. Gellyfish will choose a3a_3 in the third round, so the final value of xx will be 66.

Flower wants to maximize the final value of xx, so Flower will choose b2b_2 in the second round. Therefore, the final value of xx will be 66.

在第一个测试用例中,仅有一轮,且 Gellyfish 是该轮的活跃玩家。因此,她将选择 a1a_1,最终 xx 的值为 00。

在第二个测试用例中,Flower 将在两轮中均为活跃玩家。她将选择 a1a_1 和 b2b_2,最终 xx 的值为 a1⊕b2=15a_1 \oplus b_2 = 15。Flower 也可改为选择 b1b_1 和 a2a_2,此时同样得到 x=a2⊕b1=15x = a_2 \oplus b_1 = 15。

在第三个测试用例中,a1=b1a_1 = b_1,因此 Gellyfish 在第一轮中的选择无关紧要。在第二轮中:

  • 若 Flower 选择 a2a_2,则 xx 将变为 77;Gellyfish 在第三轮中将选择 b3b_3,因此 xx 的最终值为 44。
  • 否则,Flower 选择 b2b_2,则 xx 将变为 44;Gellyfish 在第三轮中将选择 a3a_3,因此 xx 的最终值为 66。

Flower 希望最大化 xx 的最终值,因此她在第二轮中会选择 b2b_2。故 xx 的最终值为 66。

输入解题思路,AI测评打分。不知道怎么写?

首页