CF2165C.Binary Wine

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given nn integers a1,a2,…,ana_1,a_2,\ldots,a_n within the range [0,230)[0,2^{30}).

You can spend 11 coin to increase any aia_i by 11. You can perform this operation any number of times.

You need to solve qq queries; for each query, you are given an integer cc, also in the range [0,230)[0,2^{30}). You would like it if there exists a sequence bb of length nn with the following properties:

  • For every 1≤i≤n1\le i\le n, 0≤bi≤ai0\le b_i\le a_i.
  • b1⊕b2⊕…⊕bn=cb_1\oplus b_2\oplus\ldots\oplus b_n=c, where ⊕\oplus denotes the bitwise XOR operation.

Please calculate the minimum number of coins you will have to spend, such that there exists a suitable bb.

The queries are independent, meaning that any operations you perform on the sequence aa will not impact future queries.

给你 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n,每个数均在区间 [0,230)[0,2^{30}) 内。

你可以花费 11 枚硬币将任意一个 aia_i 增加 11。该操作可执行任意多次。

你需要处理 qq 个查询;对每个查询,你将获得一个整数 cc(同样在区间 [0,230)[0,2^{30}) 内)。你希望存在一个长度为 nn 的序列 bb,满足以下条件:

  • 对每个 1≤i≤n1\le i\le n,有 0≤bi≤ai0\le b_i\le a_i;
  • b1⊕b2⊕…⊕bn=cb_1\oplus b_2\oplus\ldots\oplus b_n=c,其中 ⊕\oplus 表示按位异或运算。

请计算所需的最少硬币数,使得存在满足上述条件的序列 bb。

各查询相互独立,即你在某个查询中对序列 aa 所做的任何操作均不会影响后续查询。

输入格式

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 consists of two integers n,qn,q (1≤n≤5⋅1051\le n\le5\cdot10^5, 1≤q≤5⋅1041\le q\le5\cdot10^4) — the length of sequence aa and the number of queries.

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (0≤ai<2300\le a_i \lt 2^{30}) — the initial sequence aa.

Each of the next qq lines contains a single integer cc (0≤c<2300\le c \lt 2^{30}) — the target XOR.

It is guaranteed that the sum of nn over all test cases does not exceed 5⋅1055\cdot10^5.

It is guaranteed that the sum of qq over all test cases does not exceed 5⋅1045\cdot10^4.

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

每个测试用例的第一行包含两个整数 n,qn, q(1≤n≤5⋅1051\le n\le5\cdot10^5, 1≤q≤5⋅1041\le q\le5\cdot10^4)——分别表示序列 aa 的长度和查询次数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(0≤ai<2300\le a_i \lt 2^{30})——即初始序列 aa。

接下来的 qq 行中,每行包含一个整数 cc(0≤c<2300\le c \lt 2^{30})——表示目标异或值。

保证所有测试用例的 nn 之和不超过 5⋅1055\cdot10^5。

保证所有测试用例的 qq 之和不超过 5⋅1045\cdot10^4。

输出格式

For each query, output a single integer — the minimum coins you will have to spend, such that there exists a suitable bb.

对于每个查询,输出一个整数——即满足存在合适的 bb 时,你所需花费的最少硬币数。

输入输出样例

  • 输入#1

    4
    2 1
    5 7
    9
    3 1
    9 9 8
    24
    6 4
    1 1 4 5 1 4
    10
    20
    30
    40
    1 1
    0
    0

    输出#1

    1
    7
    3
    11
    16
    31
    0

说明/提示

In the first test case, we spend 11 coin to increase a2a_2 by 11, resulting in sequence [5,8][5,8]. A suitable bb would be [1,8][1,8]. It can be shown one cannot spend less than 11 coin to achieve the objective.

In the second test case, we can spend 77 coins to increase a1a_1 by 77, resulting in sequence [16,9,8][16,9,8]. A suitable bb would be [16,9,1][16,9,1].

在第一个测试用例中,我们花费 11 枚硬币将 a2a_2 增加 11,得到序列 [5,8][5,8]。一个合适的 bb 序列可以是 [1,8][1,8]。可以证明,无法花费少于 11 枚硬币来实现目标。

在第二个测试用例中,我们可以花费 77 枚硬币将 a1a_1 增加 77,得到序列 [16,9,8][16,9,8]。一个合适的 bb 序列可以是 [16,9,1][16,9,1]。

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

首页