CF1669H.Maximal AND

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Let AND\mathsf{AND} denote the bitwise AND operation, and OR\mathsf{OR} denote the bitwise OR operation.

You are given an array aa of length nn and a non-negative integer kk. You can perform at most kk operations on the array of the following type:

  • Select an index ii (1≤i≤n1 \leq i \leq n) and replace aia_i with aia_i OR\mathsf{OR} 2j2^j where jj is any integer between 00 and 3030 inclusive. In other words, in an operation you can choose an index ii (1≤i≤n1 \leq i \leq n) and set the jj-th bit of aia_i to 11 (0≤j≤300 \leq j \leq 30).

Output the maximum possible value of a1a_1 AND\mathsf{AND} a2a_2 AND\mathsf{AND} …\dots AND\mathsf{AND} ana_n after performing at most kk operations.

设 AND\mathsf{AND} 表示按位与运算,OR\mathsf{OR} 表示按位或运算。

给定一个长度为 nn 的数组 aa 和一个非负整数 kk。你最多可对数组执行 kk 次如下类型的操作:

  • 选择一个下标 ii(1≤i≤n1 \leq i \leq n),并将 aia_i 替换为 aia_i OR\mathsf{OR} 2j2^j,其中 jj 是 00 到 3030(含)之间的任意整数。换言之,每次操作中,你可以选择一个下标 ii(1≤i≤n1 \leq i \leq n),并将 aia_i 的第 jj 位(0≤j≤300 \leq j \leq 30)置为 11。

输出在至多执行 kk 次操作后,a1a_1 AND\mathsf{AND} a2a_2 AND\mathsf{AND} …\dots AND\mathsf{AND} ana_n 的最大可能值。

输入格式

The first line of the input contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of test cases. The description of test cases follows.

The first line of each test case contains the integers nn and kk (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 0≤k≤1090 \le k \le 10^9).

Then a single line follows, containing nn integers describing the arrays aa (0≤ai<2310 \leq a_i \lt 2^{31}).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,0≤k≤1090 \le k \le 10^9)。

接下来一行包含 nn 个整数,用于描述数组 aa(0≤ai<2310 \leq a_i \lt 2^{31})。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single line containing the maximum possible AND\mathsf{AND} value of a1a_1 AND\mathsf{AND} a2a_2 AND\mathsf{AND} …\dots AND\mathsf{AND} ana_n after performing at most kk operations.

对于每个测试用例,输出一行,包含在最多执行 kk 次操作后,a1a_1 AND\mathsf{AND} a2a_2 AND\mathsf{AND} …\dots AND\mathsf{AND} ana_n 的最大可能值。

输入输出样例

  • 输入#1

    4
    3 2
    2 1 1
    7 0
    4 6 6 28 6 6 12
    1 30
    0
    4 4
    3 1 3 1

    输出#1

    2
    4
    2147483646
    1073741825

说明/提示

For the first test case, we can set the bit 11 (212^1) of the last 22 elements using the 22 operations, thus obtaining the array [22, 33, 33], which has AND\mathsf{AND} value equal to 22.

For the second test case, we can't perform any operations so the answer is just the AND\mathsf{AND} of the whole array which is 44.

对于第一个测试用例,我们可以对最后 22 个元素执行 22 次操作,将它们的第 11 位(即 212^1)置为 11,从而得到数组 [2,3,3][2, 3, 3],其 AND\mathsf{AND} 值等于 22。

对于第二个测试用例,我们无法执行任何操作,因此答案即为整个数组的 AND\mathsf{AND} 值,也就是 44。

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

首页