CF1696A.NIT orz!

入门

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

NIT, the cleaver, is new in town! Thousands of people line up to orz him. To keep his orzers entertained, NIT decided to let them solve the following problem related to or⁡z\operatorname{or} z. Can you solve this problem too?

You are given a 1-indexed array of nn integers, aa, and an integer zz. You can do the following operation any number (possibly zero) of times:

  • Select a positive integer ii such that 1≤i≤n1\le i\le n. Then, simutaneously set aia_i to (aior⁡z)(a_i\operatorname{or} z) and set zz to (aiand⁡z)(a_i\operatorname{and} z). In other words, let xx and yy respectively be the current values of aia_i and zz. Then set aia_i to (xor⁡y)(x\operatorname{or}y) and set zz to (xand⁡y)(x\operatorname{and}y).

Here or⁡\operatorname{or} and and⁡\operatorname{and} denote the bitwise operations OR and AND respectively.

Find the maximum possible value of the maximum value in aa after any number (possibly zero) of operations.

NIT(“切刀”)初来乍到!成千上万的人排起长队向他膜拜(orz)。为了不让这些膜拜者感到无聊,NIT 决定让他们解决一个与 or⁡z\operatorname{or} z 相关的问题。你也能解决这个问题吗?

给定一个长度为 nn 的、下标从 1 开始的整数数组 aa,以及一个整数 zz。你可以执行以下操作任意多次(也可以不执行):

  • 选择一个正整数 ii,满足 1≤i≤n1 \le i \le n。然后同时将 aia_i 更新为 (aior⁡z)(a_i \operatorname{or} z),并将 zz 更新为 (aiand⁡z)(a_i \operatorname{and} z)。换句话说,设 xx 和 yy 分别为当前的 aia_i 和 zz 的值,则将 aia_i 设为 (xor⁡y)(x \operatorname{or} y),并将 zz 设为 (xand⁡y)(x \operatorname{and} y)。

其中,or⁡\operatorname{or} 和 and⁡\operatorname{and} 分别表示按位或(OR)和按位与(AND)运算。

求:在执行任意次数(包括零次)操作后,数组 aa 中最大值所能达到的最大可能值。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). Description of the test cases follows.

The first line of each test case contains two integers nn and zz (1≤n≤20001\le n\le 2000, 0≤z<2300\le z \lt 2^{30}).

The second line of each test case contains nn integers a1a_1,a2a_2,…\ldots,ana_n (0≤ai<2300\le a_i \lt 2^{30}).

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

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

每个测试用例的第一行包含两个整数 nn 和 zz(1≤n≤20001\le n\le 2000,0≤z<2300\le z \lt 2^{30})。

每个测试用例的第二行包含 nn 个整数 a1a_1、a2a_2、…\ldots、ana_n(0≤ai<2300\le a_i \lt 2^{30})。

保证所有测试用例的 nn 之和不超过 10410^4。

输出格式

For each test case, print one integer — the answer to the problem.

对于每个测试用例,输出一个整数——即该问题的答案。

输入输出样例

  • 输入#1

    5
    2 3
    3 4
    5 5
    0 2 4 6 8
    1 9
    10
    5 7
    7 15 30 29 27
    3 39548743
    10293834 10284344 13635445

    输出#1

    7
    13
    11
    31
    48234367

说明/提示

In the first test case of the sample, one optimal sequence of operations is:

  • Do the operation with i=1i=1. Now a1a_1 becomes (3or⁡3)=3(3\operatorname{or}3)=3 and zz becomes (3and⁡3)=3(3\operatorname{and}3)=3.
  • Do the operation with i=2i=2. Now a2a_2 becomes (4or⁡3)=7(4\operatorname{or}3)=7 and zz becomes (4and⁡3)=0(4\operatorname{and}3)=0.
  • Do the operation with i=1i=1. Now a1a_1 becomes (3or⁡0)=3(3\operatorname{or}0)=3 and zz becomes (3and⁡0)=0(3\operatorname{and}0)=0.

After these operations, the sequence aa becomes [3,7][3,7], and the maximum value in it is 77. We can prove that the maximum value in aa can never exceed 77, so the answer is 77.

In the fourth test case of the sample, one optimal sequence of operations is:

  • Do the operation with i=1i=1. Now a1a_1 becomes (7or⁡7)=7(7\operatorname{or}7)=7 and zz becomes (7and⁡7)=7(7\operatorname{and}7)=7.
  • Do the operation with i=3i=3. Now a3a_3 becomes (30or⁡7)=31(30\operatorname{or}7)=31 and zz becomes (30and⁡7)=6(30\operatorname{and}7)=6.
  • Do the operation with i=5i=5. Now a5a_5 becomes (27or⁡6)=31(27\operatorname{or}6)=31 and zz becomes (27and⁡6)=2(27\operatorname{and}6)=2.

在样例的第一个测试用例中,一种最优的操作序列如下:

  • 对 i=1i=1 执行操作。此时 a1a_1 变为 (3or⁡3)=3(3\operatorname{or}3)=3,且 zz 变为 (3and⁡3)=3(3\operatorname{and}3)=3。
  • 对 i=2i=2 执行操作。此时 a2a_2 变为 (4or⁡3)=7(4\operatorname{or}3)=7,且 zz 变为 (4and⁡3)=0(4\operatorname{and}3)=0。
  • 对 i=1i=1 执行操作。此时 a1a_1 变为 (3or⁡0)=3(3\operatorname{or}0)=3,且 zz 变为 (3and⁡0)=0(3\operatorname{and}0)=0。

经过上述操作后,序列 aa 变为 [3,7][3,7],其最大值为 77。我们可以证明 aa 中的最大值不可能超过 77,因此答案为 77。

在样例的第四个测试用例中,一种最优的操作序列如下:

  • 对 i=1i=1 执行操作。此时 a1a_1 变为 (7or⁡7)=7(7\operatorname{or}7)=7,且 zz 变为 (7and⁡7)=7(7\operatorname{and}7)=7。
  • 对 i=3i=3 执行操作。此时 a3a_3 变为 (30or⁡7)=31(30\operatorname{or}7)=31,且 zz 变为 (30and⁡7)=6(30\operatorname{and}7)=6。
  • 对 i=5i=5 执行操作。此时 a5a_5 变为 (27or⁡6)=31(27\operatorname{or}6)=31,且 zz 变为 (27and⁡6)=2(27\operatorname{and}6)=2。

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

首页