QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#3901. 无聊的游戏

統計

Nim 是一种两人博弈游戏,双方轮流从不同的堆中移除物品。每一回合,玩家必须至少移除一个物品,且可以移除任意数量的物品,前提是这些物品必须来自同一个堆。取走最后一个物品的玩家获胜。

给定大小为 $a_0, a_1, \dots, a_n$ 的堆。请找到一个满足以下要求的堆子序列 $S$:

  • 如果我们使用该子序列中的堆进行最优的“Nim”游戏,先手必败。
  • $a_0 \in S$。

你还需要处理 $m$ 个修改堆序列的查询:第 $i$ 个查询 $p_i, x_i$ 表示从现在起 $a_{p_i} = x_i$。每次修改后,都需要找到满足上述要求的子序列 $S_i$。

保证初始状态以及每次修改查询后,满足条件的子序列 $S$ 恰好只有一个。

输入格式

第一行包含两个空格分隔的整数 $n$ 和 $m$。

第二行包含 $n + 1$ 个空格分隔的整数 $a_0, a_1, \dots, a_n$。

接下来的 $m$ 行包含修改查询的描述,第 $i$ 行包含两个空格分隔的整数 $t_i, x_i$。为了计算 $p_i$,你需要知道上一个问题的答案。具体来说,如果你在上一个问题的答案中输出了数字 $k, b_1, b_2, \dots, b_k$,那么 $p_i = t_i \oplus k \oplus b_1 \oplus b_2 \oplus \dots \oplus b_k$。

数据范围

$2 \le n \le 1000$ $0 \le m \le 1000$ $0 \le a_0, a_1, \dots, a_n < 2^n$ $0 \le p_i \le n$ $0 \le x_i < 2^n$

输出格式

第一行输出整数 $k$ —— 子序列 $S$ 的大小。

第二行输出空格分隔的整数序列 $b_1 < b_2 < \dots < b_k$,其中 $S = a_{b_1}, a_{b_2}, \dots, a_{b_k}$。

在每次第 $i$ 个查询后,以相同的格式输出子序列 $S_i$。

样例

样例输入 1

3 1
5 6 2 7
0 3

样例输出 1

3
0 2 3
3
0 1 2

样例输入 2

3 2
1 2 3 4
0 2
2 6

样例输出 2

3
0 1 2
2
0 1
3
0 1 3

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.