QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 256 MB Points totaux : 100 Interactif

#2373. 寻找数组

Statistiques

这是一个交互式问题。

有一个长度为 $n$ 的数组 $a$,由不同的整数组成。保证数组中的每个元素都是小于或等于 $10^9$ 的正整数。你需要找出数组中所有元素的值。

为此,你可以进行最多 30 次以下两种类型的查询:

  • “1 $i$” ($1 \le i \le n$) —— 询问 $a_i$ 的值。
  • “2 $k$ $i_1, i_2, \dots, i_k$” ($2 \le k \le n$, $1 \le i_j \le n$, 所有 $i_j$ 必须互不相同) —— 询问 $k$ 个位置的元素。作为该查询的回答,你将收到 $\frac{k(k-1)}{2}$ 个整数 —— 对于每一对 $c < d$,返回 $|a_{i_c} - a_{i_d}|$。换句话说,你将收到位于位置 $i_1, i_2, \dots, i_k$ 的所有元素两两之间的绝对差值。注意,查询 2 的回答是随机打乱的。

当你确定答案后,请使用以下查询将其打印出来:

  • “3 $a_1, a_2, \dots, a_n$” ($1 \le a_i \le 10^9$) —— 数组 $a$ 的元素。执行此查询后,你的程序必须终止。此查询不计入查询次数(即你可以进行最多 30 次前两种类型的查询,外加 1 次第三种类型的查询)。

交互

首先,你的程序应读取一个整数 $n$ ($1 \le n \le 250$),即元素的数量。

要进行第一种类型的查询,请打印 “1 $i$” ($1 \le i \le n$)。在此查询后,读取一个整数 —— $a_i$ 的值。

要进行第二种类型的查询,请打印 “2 $k$”。然后在同一行打印 $k$ 个以空格分隔的互不相同的整数 $i_1, i_2, \dots, i_k$ ($1 \le i_j \le n$)。在此查询后,读取 $\frac{k(k-1)}{2}$ 个整数 —— 对于每一对 $c < d$,返回 $|a_{i_c} - a_{i_d}|$。这些值将以随机顺序给出。

当你确定答案后,打印 “3”。然后在同一行打印 $n$ 个以空格分隔的整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$)。你的程序必须在此查询后终止。

如果对于前两种查询中的任何一种,你得到的回答是 $-1$,则意味着你进行的查询次数超过了允许的范围,或者进行了无效的查询。你的程序应立即终止(例如,通过调用 exit(0))。你将收到 “Wrong Answer”。如果你忽略这一点,由于程序将继续从关闭的流中读取,你可能会得到其他判决结果。

打印查询后,请务必输出换行符并刷新输出。否则,你可能会得到 Wall time-limit exceeded。为此,请使用:

  • C++ 中的 fflush(stdout)cout.flush()
  • Java 中的 System.out.flush()
  • Python 中的 stdout.flush()

请严格遵守此交互格式。

样例

输入 1

3
1
2
4 3 1

输出 1

1 1
1 2
2 3 1 2 3
3 1 2 5

说明

在第一次类型 1 的查询中,我们询问 $a_1$ 的值并得到 1 作为回答。

在第二次类型 1 的查询中,我们询问 $a_2$ 的值并得到 2 作为回答。

在类型 2 的查询中,我们询问索引为 1, 2 和 3 的数组元素之间所有可能的差值。我们得到数组 4, 3, 1 作为结果。我们知道数组包含 $|a_1 - a_2|, |a_1 - a_3|, |a_2 - a_3|$。由于我们已经知道 $|a_2 - a_1| = 1$,以下情况之一成立:$|a_1 - a_3| = 3$ 且 $|a_2 - a_3| = 4$,或者 $|a_2 - a_3| = 3$ 且 $|a_1 - a_3| = 4$。考虑到问题的约束,唯一可能的情况是 $|a_1 - a_3| = 4$ 且 $|a_2 - a_3| = 3$,此时 $a_3 = 5$。

既然我们知道了数组中所有元素的值,我们在最后一次查询中将它们打印出来。

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.