QOJ.ac

QOJ

Límite de tiempo: 3.0 s Límite de memoria: 1024 MB Puntuación total: 100 Comunicación Hackeable ✓

#17760. 心灵感应

Estadísticas

这是一个多阶段(multi-pass)问题。

Alice 和 Bob 正在为 Christina 表演一个心灵感应魔术。Christina 选择了一个子集 $S \subset \{1, 2, \dots, n\}$,满足 $|S| < \frac{n}{2}$。然后,Alice 向该子集中添加一个整数 $x$,满足 $x \in \{1, 2, \dots, n\}$ 且 $x \notin S$。Bob 只会得到 Alice 添加元素后的结果集合,并且需要推断出 Alice 具体添加了哪一个整数。

交互

在每个测试点上,您的程序将被执行两次。在第一次运行中,您的程序扮演 Alice。在第二次运行中,您的程序扮演 Bob。

每次运行中都包含多组测试数据。

第一次运行

输入的第一行包含字符串 Alice。第二行包含一个整数 $T$ ($1 \le T \le 5 \times 10^5$),表示测试数据组数。对于每组测试数据:

第一行输入包含两个整数 $n$ 和 $k$ ($3 \le n \le 10^6$,$1 \le k < \frac{n}{2}$)。第二行包含 $k$ 个互不相同的整数 $a_1, a_2, \dots, a_k$ ($1 \le a_i \le n$),表示 Christina 选择的子集。

对于每组测试数据,您的程序应该输出一行,包含 $k + 1$ 个互不相同的整数 $b_1, b_2, \dots, b_{k+1}$ ($1 \le b_i \le n$),使得 $\{a_1, a_2, \dots, a_k\} \subset \{b_1, b_2, \dots, b_{k+1}\}$。

第二次运行

您的程序将在第二次运行中被重新启动。

输入的第一行包含字符串 Bob。第二行包含一个整数 $T$ ($1 \le T \le 5 \times 10^5$),表示测试数据组数。对于每组测试数据:

第一行输入包含两个整数 $n$ 和 $k$ ($3 \le n \le 10^6$,$1 \le k < \frac{n}{2}$)。第二行包含 $k + 1$ 个互不相同的整数 $b_1, b_2, \dots, b_{k+1}$ ($1 \le b_i \le n$),这正是您在第一次运行中针对该测试数据输出的集合(顺序可能不同)。

对于每组测试数据,您的程序应该输出一行,包含一个整数,表示您在第一次运行中添加的那个整数。

请注意,第二次运行中测试数据的顺序可能与第一次运行中的顺序不同。如果您能对所有测试数据正确推断出添加的整数,则您的程序被视为正确。

保证所有测试数据的 $n$ 之和不超过 $3 \times 10^6$。

样例

输入格式 1

Alice
2
7 3
3 1 5
5 1
2
Bob
2
5 1
3 2
7 3
3 5 1 6

输出格式 1

5 6 1 3
3 2
3
6

说明

该样例展示了某解决方案在样例测试数据上的两次运行过程。

在第一次运行中,对于第一组样例测试数据,Christina 从 $\{1, 2, \dots, 7\}$ 中选择了子集 $S = \{1, 3, 5\}$(输入为 3 1 5),满足 $|S| = 3 < \frac{7}{2}$。Alice 必须添加一个不在 $S$ 中的额外整数,并输出大小为 4 的结果集合。她选择添加整数 6,因此她输出了集合 $\{1, 3, 5, 6\}$(顺序为 5 6 1 3)。

在第二次运行中,第二组样例测试数据对应于第一次运行中的第一组样例测试数据。Bob 收到 $(n, k) = (7, 3)$ 以及集合 $\{1, 3, 5, 6\}$(输入为 3 5 1 6)。利用 Alice 和 Bob 之间预先约定的策略,他可以推断出 6 是添加的整数,并输出 6。

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.