ユニークビジョンプログラミングコンテスト2025 秋(AtCoder Beginner Contest 425)
G
Sum of Min of XOR
AtCoder
⌀ 2205
原题
← F→
翻译中…

Problem Statement

翻译中…

You are given positive integers $N,M$ and a sequence of non-negative integers $A=(A_1,A_2,\ldots,A_N)$ of length $N$.

翻译中…

Find $\displaystyle \sum_{x=0}^{M-1} \min_{1\le i\le N} \left(x\oplus A_i \right)$.

翻译中…

Here, $x\oplus A_i$ represents the bitwise $\mathrm{XOR}$ of $x$ and $A_i$.

翻译中…

What is bitwise $\mathrm{XOR}$ operation? The bitwise $\mathrm{XOR}$ of non-negative integers $X,Y$, $X \oplus Y$, is defined as follows: When $X \oplus Y$ is written in binary, the digit in the $2^k$ ($k \geq 0$) place is $1$ if exactly one of $X,Y$ has $1$ in the $2^k$ place when written in binary, and $0$ otherwise. For example, $3 \oplus 5 = 6$ (in binary representation: $011 \oplus 101 = 110$).

翻译中…

Constraints

翻译中…
  • $1\le N\le 2\times 10^5$
  • $1\le M\le 10^9$
  • $0\le A_i \le 10^9$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N M
A_1 A_2 \ldots A_N

翻译中…

Output

翻译中…

Output the answer.

翻译中…

样例

Input #1
2 4
1 2
Output #1
2
- When $x=0$: $x\oplus A_1=1,x\oplus A_2= 2$, so $\displaystyle \min_{1\le i\le N} \left(x\oplus A_i \right) = 1$. - When $x=1$: $x\oplus A_1=0,x\oplus A_2= 3$, so $\displaystyle \min_{1\le i\le N} \left(x\oplus A_i \right) = 0$. - When $x=2$: $x\oplus A_1=3,x\oplus A_2= 0$, so $\displaystyle \min_{1\le i\le N} \left(x\oplus A_i \right) = 0$. - When $x=3$: $x\oplus A_1=2,x\oplus A_2= 1$, so $\displaystyle \min_{1\le i\le N} \left(x\oplus A_i \right) = 1$. Therefore, output $1+0+0+1=2$.
Input #2
6 5
0 1 2 3 4 5
Output #2
0
Input #3
10 8762
347 883 264 816 533 306 190 880 624 279
Output #3
34912221
题目信息

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