QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100

#4579. 异或对

统计

XOR 是一种位运算,当且仅当对应的输入位不同(一个是 1 而另一个是 0)时,结果位为 1。XOR 运算符通常用符号 $\oplus$ 表示,或者在大多数编程语言中用字符 ^(脱字符)表示。例如,$(10 \oplus 6) = 12$。

在本题中,给定一个整数 $N$ 和一个整数集合 $S_{1..M}$。你的任务是计算有多少对整数 $\langle A, B \rangle$ 满足 $1 \le A, B \le (A \oplus B) \le N$ 且 $(A \oplus B) \notin S$。

例如,设 $N = 10$ 且 $S_{1..4} = \{4, 6, 7, 10\}$。有 6 对 $\langle A, B \rangle$ 满足条件: $1, 2 \to (1 \oplus 2) = 3$ $1, 4 \to (1 \oplus 4) = 5$ $1, 8 \to (1 \oplus 8) = 9$ $2, 1 \to (2 \oplus 1) = 3$ $4, 1 \to (4 \oplus 1) = 5$ $8, 1 \to (8 \oplus 1) = 9$

注意,像 $\langle 2, 4 \rangle$ 这样的对不满足此示例的条件,因为 $(2 \oplus 4) = 6$,但 $6 \in S$。另一个对如 $\langle 5, 1 \rangle$ 也不满足条件,因为它违反了 $A, B \le (A \oplus B)$ 的要求。

输入格式

输入的第一行包含两个整数 $N$ 和 $M$ ($1 \le N \le 10^6$; $1 \le M \le 100\,000$),分别表示给定的 $N$ 和整数集合 $S_{1..M}$ 的大小。下一行包含 $M$ 个整数 $S_i$ ($1 \le S_i \le 10^6$),表示集合 $S_{1..M}$ 中的元素。

输出格式

输出一行,包含一个整数,表示满足 $1 \le A, B \le (A \oplus B) \le N$ 且 $(A \oplus B) \notin S_{1..M}$ 的对 $\langle A, B \rangle$ 的数量。

样例

样例输入 1

10 4
4 6 7 10

样例输出 1

6

说明 1

这是题目描述中的示例。

样例输入 2

8 5
4 3 5 8 1

样例输出 2

10

说明 2

有 10 对 $\langle A, B \rangle$ 满足条件: $1, 6 \to (1 \oplus 6) = 7$ $2, 4 \to (2 \oplus 4) = 6$ $2, 5 \to (2 \oplus 5) = 7$ $3, 4 \to (3 \oplus 4) = 7$ $3, 5 \to (3 \oplus 5) = 6$ $4, 2 \to (4 \oplus 2) = 6$ $4, 3 \to (4 \oplus 3) = 7$ $5, 2 \to (5 \oplus 2) = 7$ $5, 3 \to (5 \oplus 3) = 6$ $6, 1 \to (6 \oplus 1) = 7$

样例输入 3

20 7
3 7 18 15 12 18 19

样例输出 3

50

样例输入 4

5 6
1 2 3 4 5 6

样例输出 4

0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.