QOJ.ac

QOJ

时间限制: 5.0 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#11763. 分配律

统计

给定一个包含 $n$ 个不同整数的集合 $S$。你将收到 $q$ 次查询,每次查询属于以下两种类型之一:

  1. 类型 1 查询 ($1\ x$):

    • 如果 $x$ 当前在集合 $S$ 中,将其移除。
    • 否则,将 $x$ 加入集合 $S$。
  2. 类型 2 查询 ($2\ t$):

    • 输出集合 $S$ 中所有 $x$ 的 $(x + t)$ 的按位异或和。形式化地,输出 $\bigoplus_{x \in S} (x + t)$。

输入格式

输入的第一行包含两个整数 $n$ 和 $q$ ($1 \le n, q \le 3 \cdot 10^5$),分别表示集合的初始大小和查询次数。

输入的下一行包含 $n$ 个不同的整数 $x_1, x_2 \dots x_n$ ($0 \le x_i < 2^{20}$),表示初始集合。

接下来的 $q$ 行描述查询。每行包含一个形如 $1\ x$ 或 $2\ t$ 的查询 ($0 \le x, t < 2^{20}$),表示上述格式的查询。

保证至少存在一次类型 2 的查询。

输出格式

对于每次类型 2 的查询,输出集合 $S$ 中所有 $x$ 的 $(x + t)$ 的按位异或和。

样例

输入 1

3 10
1 6 15
2 0
1 5
1 6
1 10
2 3
2 12
1 15
2 7
1 0
2 7

输出 1

8
19
17
21
18

说明

在样例中,第一次类型 2 查询时,集合为 $S = \{1, 6, 15\}$。由于该查询中 $t = 0$,我们输出的值为: $$(1 + 0) \oplus (6 + 0) \oplus (15 + 0) = 1 \oplus 6 \oplus 15 = 8$$

在第二次类型 2 查询时,集合为 $S = \{1, 5, 10, 15\}$。由于该查询中 $t = 3$,我们输出的值为: $$(1 + 3) \oplus (5 + 3) \oplus (10 + 3) \oplus (15 + 3) = 4 \oplus 8 \oplus 13 \oplus 18 = 19$$

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.