CF1669H.Maximal AND
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let AND denote the bitwise AND operation, and OR denote the bitwise OR operation.
You are given an array a of length n and a non-negative integer k. You can perform at most k operations on the array of the following type:
- Select an index i (1≤i≤n) and replace ai with ai OR 2j where j is any integer between 0 and 30 inclusive. In other words, in an operation you can choose an index i (1≤i≤n) and set the j-th bit of ai to 1 (0≤j≤30).
Output the maximum possible value of a1 AND a2 AND … AND an after performing at most k operations.
给定一个长度为 n 的数组 a 和一个非负整数 k。你最多可对数组执行 k 次如下类型的操作:
- 选择一个下标 i(1≤i≤n),并将 ai 替换为 ai OR 2j,其中 j 是 0 到 30(含)之间的任意整数。换言之,每次操作中,你可以选择一个下标 i(1≤i≤n),并将 ai 的第 j 位(0≤j≤30)置为 1。
输出在至多执行 k 次操作后,a1 AND a2 AND … AND an 的最大可能值。
输入格式
The first line of the input contains a single integer t (1≤t≤100) — the number of test cases. The description of test cases follows.
The first line of each test case contains the integers n and k (1≤n≤2⋅105, 0≤k≤109).
Then a single line follows, containing n integers describing the arrays a (0≤ai<231).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
输入的第一行包含一个整数 t(1≤t≤100),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 k(1≤n≤2⋅105,0≤k≤109)。
接下来一行包含 n 个整数,用于描述数组 a(0≤ai<231)。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output a single line containing the maximum possible AND value of a1 AND a2 AND … AND an after performing at most k operations.
对于每个测试用例,输出一行,包含在最多执行 k 次操作后,a1 AND a2 AND … AND an 的最大可能值。
输入输出样例
输入#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 1 (21) of the last 2 elements using the 2 operations, thus obtaining the array [2, 3, 3], which has AND value equal to 2.
For the second test case, we can't perform any operations so the answer is just the AND of the whole array which is 4.
对于第一个测试用例,我们可以对最后 2 个元素执行 2 次操作,将它们的第 1 位(即 21)置为 1,从而得到数组 [2,3,3],其 AND 值等于 2。
对于第二个测试用例,我们无法执行任何操作,因此答案即为整个数组的 AND 值,也就是 4。
输入解题思路,AI测评打分。不知道怎么写?