Pinely Round 5 (Div. 1 + Div. 2)
G
Bitwise And Equals
Codeforces
3500
原题
← FH →
翻译中…

There is an array of integers $a_1, a_2, \ldots, a_n$, and there is an integer $X$.

翻译中…

You may perform the following operation zero or more times:

翻译中…
  • Select $i$, and increase $a_i$ by one.
翻译中…

Let $a'$ be the final state of the array. Your goal is to perform the operation above the smallest number of times such that $a'_1 \,\&\, a'_2 \,\&\, \ldots \,\&\, a'_n = X$. $\&$ denotes the bitwise AND operation.

翻译中…

There are $q$ such query integers $X$: $X_1, X_2, \ldots, X_q$. Compute the answer for each $X = X_i$. Note that all queries are processed separately and independently, from the same initial state $a$.

翻译中…

Input

翻译中…

The first line contains integers $n$ and $q$ ($2 \le n \le 200\,000$, $1 \le q \le 200\,000$) — the length of the array and the number of queries.

翻译中…

The second line contains integers $a_1, a_2, \ldots, a_n$ (for each $i$, $0 \le a_i \lt 2^{20}$).

翻译中…

The next $q$ lines each contain a single integer $X_i$ ($0 \le X_i \lt 2^{20}$).

翻译中…

Output

翻译中…

For each query $i$ out of $q$, print the smallest number of operations to get to the array $a'$ such that $a'_1 \,\&\, a'_2 \,\&\, \ldots \,\&\, a'_n = X_i$.

翻译中…

It's possible to show, that it's always possible to obtain such array $a'$ in finite number of operations.

翻译中…

Note

翻译中…

For the first query, you can increase $i = 3$ ($a_i = 7$) and get the array $a = [6, 4, 8, 5, 4]$, then $6 \,\&\, 4 \,\&\, 8 \,\&\, 5 \,\&\, 4 = 0$.

翻译中…

For the third query, original array already matches condition: $6 \,\&\, 4 \,\&\, 7 \,\&\, 5 \,\&\, 4 = 4$.

翻译中…

样例

Input #1
5 4
6 4 7 5 4
0
2
4
6
Output #1
1
8
0
5
InputCopy OutputCopy
题目信息
题号
2161G
时间限制
3 s
内存限制
512 MB
标签
位运算
贪心

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