309540: CF1696A. NIT orz!

Memory Limit:512 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

NIT orz!

题意翻译

NIT,是镇上新来的!成千的人排队要 orz 他。为了让他的 orzers 高兴,NIT 决定让他们解决与 $\operatorname{or} z$ 有关的问题。你也能解决这个问题吗? 给你一个以 $1$ 为初始下标,包含 $n$ 个整数的数组 $a$ 和一个整数 $z$。你可以做以下操作的任意次(可能为零): - 选择正整数 $i$ 满足 $1\le i\le n$。然后将 $a_i$ 赋值为 $(a_i\operatorname{or} z)$,将 $z$ 赋值为 $(a_i \operatorname{and} z)$。换句话说,设 $x$ 和 $y$ 分别为 $a_i$ 和 $z$,然后将 $a_i$ 赋值为 $(x \operatorname{or} y)$,将 $z$ 赋值为 $(x \operatorname{and} y)$。 这里 $\operatorname{or}$ 和 $\operatorname{and}$ 分别表示[位运算 or 和 and](https://en.wikipedia.org/wiki/Bitwise_operation)。 在任意(可能为零)次操作后,找出最大的 $a$ 中的最大值。

题目描述

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 $ \operatorname{or} z $ . Can you solve this problem too? You are given a 1-indexed array of $ n $ integers, $ a $ , and an integer $ z $ . You can do the following operation any number (possibly zero) of times: - Select a positive integer $ i $ such that $ 1\le i\le n $ . Then, simutaneously set $ a_i $ to $ (a_i\operatorname{or} z) $ and set $ z $ to $ (a_i\operatorname{and} z) $ . In other words, let $ x $ and $ y $ respectively be the current values of $ a_i $ and $ z $ . Then set $ a_i $ to $ (x\operatorname{or}y) $ and set $ z $ to $ (x\operatorname{and}y) $ . Here $ \operatorname{or} $ and $ \operatorname{and} $ denote the [bitwise operations OR and AND](https://en.wikipedia.org/wiki/Bitwise_operation) respectively. Find the maximum possible value of the maximum value in $ a $ after any number (possibly zero) of operations.

输入输出格式

输入格式


Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 100 $ ). Description of the test cases follows. The first line of each test case contains two integers $ n $ and $ z $ ( $ 1\le n\le 2000 $ , $ 0\le z<2^{30} $ ). The second line of each test case contains $ n $ integers $ a_1 $ , $ a_2 $ , $ \ldots $ , $ a_n $ ( $ 0\le a_i<2^{30} $ ). It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 10^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=1 $ . Now $ a_1 $ becomes $ (3\operatorname{or}3)=3 $ and $ z $ becomes $ (3\operatorname{and}3)=3 $ . - Do the operation with $ i=2 $ . Now $ a_2 $ becomes $ (4\operatorname{or}3)=7 $ and $ z $ becomes $ (4\operatorname{and}3)=0 $ . - Do the operation with $ i=1 $ . Now $ a_1 $ becomes $ (3\operatorname{or}0)=3 $ and $ z $ becomes $ (3\operatorname{and}0)=0 $ . After these operations, the sequence $ a $ becomes $ [3,7] $ , and the maximum value in it is $ 7 $ . We can prove that the maximum value in $ a $ can never exceed $ 7 $ , so the answer is $ 7 $ . In the fourth test case of the sample, one optimal sequence of operations is: - Do the operation with $ i=1 $ . Now $ a_1 $ becomes $ (7\operatorname{or}7)=7 $ and $ z $ becomes $ (7\operatorname{and}7)=7 $ . - Do the operation with $ i=3 $ . Now $ a_3 $ becomes $ (30\operatorname{or}7)=31 $ and $ z $ becomes $ (30\operatorname{and}7)=6 $ . - Do the operation with $ i=5 $ . Now $ a_5 $ becomes $ (27\operatorname{or}6)=31 $ and $ z $ becomes $ (27\operatorname{and}6)=2 $ .

Input

题意翻译

NIT,是镇上新来的!成千的人排队要 orz 他。为了让他的 orzers 高兴,NIT 决定让他们解决与 $\operatorname{or} z$ 有关的问题。你也能解决这个问题吗? 给你一个以 $1$ 为初始下标,包含 $n$ 个整数的数组 $a$ 和一个整数 $z$。你可以做以下操作的任意次(可能为零): - 选择正整数 $i$ 满足 $1\le i\le n$。然后将 $a_i$ 赋值为 $(a_i\operatorname{or} z)$,将 $z$ 赋值为 $(a_i \operatorname{and} z)$。换句话说,设 $x$ 和 $y$ 分别为 $a_i$ 和 $z$,然后将 $a_i$ 赋值为 $(x \operatorname{or} y)$,将 $z$ 赋值为 $(x \operatorname{and} y)$。 这里 $\operatorname{or}$ 和 $\operatorname{and}$ 分别表示[位运算 or 和 and](https://en.wikipedia.org/wiki/Bitwise_operation)。 在任意(可能为零)次操作后,找出最大的 $a$ 中的最大值。

Output

**题目大意:**
NIT是镇上新来的人,很多人排队要向他致敬(orz)。为了让他的支持者高兴,NIT决定让他们解决一个与位运算“或”(or)和“与”(and)有关的问题。你需要解决的是,给定一个初始下标为1的包含n个整数的数组a和一个整数z,你可以进行任意次数(可能为零)的操作:选择一个满足1≤i≤n的正整数i,然后将a_i赋值为(a_i或z),将z赋值为(a_i与z)。在任意次数(可能为零)的操作后,找出数组a中的最大值。

**输入数据格式:**
每个测试用例包含多个测试案例。第一行包含测试案例的数量t(1≤t≤100)。接下来是每个测试案例的描述。

每个测试案例的第一行包含两个整数n和z(1≤n≤2000,0≤z<2^30)。

每个测试案例的第二行包含n个整数a_1, a_2, ..., a_n(0≤a_i<2^30)。

保证所有测试案例的n之和不超过10^4。

**输出数据格式:**
对于每个测试案例,输出一个整数,即问题的答案。

**输入输出样例:**
输入样例 #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
```**题目大意:** NIT是镇上新来的人,很多人排队要向他致敬(orz)。为了让他的支持者高兴,NIT决定让他们解决一个与位运算“或”(or)和“与”(and)有关的问题。你需要解决的是,给定一个初始下标为1的包含n个整数的数组a和一个整数z,你可以进行任意次数(可能为零)的操作:选择一个满足1≤i≤n的正整数i,然后将a_i赋值为(a_i或z),将z赋值为(a_i与z)。在任意次数(可能为零)的操作后,找出数组a中的最大值。 **输入数据格式:** 每个测试用例包含多个测试案例。第一行包含测试案例的数量t(1≤t≤100)。接下来是每个测试案例的描述。 每个测试案例的第一行包含两个整数n和z(1≤n≤2000,0≤z<2^30)。 每个测试案例的第二行包含n个整数a_1, a_2, ..., a_n(0≤a_i<2^30)。 保证所有测试案例的n之和不超过10^4。 **输出数据格式:** 对于每个测试案例,输出一个整数,即问题的答案。 **输入输出样例:** 输入样例 #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 ```

加入题单

算法标签: