Codeforces Global Round 29 (Div. 1 + Div. 2)
E
Maximum OR Popcount
Codeforces
2300
原题
← DF →
翻译中…

You are given an array of $n$ non-negative integers.

翻译中…

You want to answer given $q$ independent scenarios. In the $i$-th scenario, you are allowed to perform the following operation at most $b_i$ times:

翻译中…
  • Choose an element of the array and increase it by $1$.
翻译中…

Your goal is to maximize the number of bits that are equal to $1$ in the bitwise OR of all numbers in the array. Find this number for each scenario.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^3$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $q$ ($1 \leq n, q \leq 10^{5}$) — the size of the array and the number of scenarios.

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq 10^{9}$) — the elements of the array.

翻译中…

The $i$-th of the next $q$ lines contains a single integer $b_i$ ($0 \leq b_i \leq 10^{9}$) — the maximum number of operations allowed in the $i$-th scenario.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^{5}$, and the sum of $q$ over all test cases does not exceed $10^{5}$.

翻译中…

Output

翻译中…

For each test case, output $q$ lines, the $i$-th of them containing a single integer — the maximum possible number of bits equal to $1$ in the bitwise OR in the $i$-th scenario.

翻译中…

Note

翻译中…
翻译中…

In the first test case:

翻译中…
  • In the first scenario, we don't have any operations, and therefore the answer is equal to the number of $1$-bits in the bitwise OR of the original array, $0$, which has $0$ bits set in its binary representation.
  • In the second scenario, one way of achieving $1$ bit set in the bitwise OR is increasing $a_1$ by $1$ twice, obtaining a bitwise OR of $2={(10)}_2$. It can be shown that it is the best possible value we can obtain by performing the operation at most twice.
  • In the third scenario, one way of achieving a result of $2$ is adding $1$ to $a_1$ three times, which can be shown to be optimal. Note that you don't have to apply the operation $4$ times.
翻译中…

In the second test case:

翻译中…
  • In the first scenario, we don't have any operations, and therefore the answer is equal to the number of $1$-bits in the bitwise OR of the original array, which is $2$.
  • In the second scenario, one way of achieving a result of $3$ is adding $1$ to $a_2$ three times, which can be shown to be optimal.
翻译中…

样例

Input #1
3
1 3
0
0
2
4
2 2
1 3
0
3
2 1
1000000000 1000000000
1000000000
Output #1
0
1
2
2
3
31
InputCopy OutputCopy
题目信息
题号
2147E
时间限制
2 s
内存限制
256 MB
标签
二分
位运算
暴力
数据结构
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。