QOJ.ac

QOJ

时间限制: 3 s 内存限制: 2048 MB 总分: 100 难度: [显示] 交互 可 Hack ✓

#18206. 猜排列

统计

这是一个交互式问题。请记得在每次输出后清空输出缓冲区。你可以使用以下方法清空输出:

  • C/C++ 中的 fflush(stdout)cout.flush()
  • Java 和 Kotlin 中的 System.out.flush()
  • Python 中的 sys.stdout.flush()
  • 其他语言请参阅相关文档。

小青鱼(Little Cyan Fish)有一个长度为 $n + 1$ 的秘密排列 $p_0, p_1, \dots, p_n$,由 $0$ 到 $n$ 的整数组成。他希望你猜出这个秘密排列。为此,小青鱼允许你进行不超过 $1024$ 次如下形式的询问:

  • ? i j:获取满足 $p_k = |p_i - p_j|$ 的下标 $k$($0 \le k \le n$)。

当然,为了进行合法的询问,你必须保证 $i$ 和 $j$ 是 $[0, n]$ 范围内的两个整数。例如,如果 $p_0 = 2, p_1 = 0, p_2 = 1$,那么询问 ? 0 2 将返回下标 $2$,因为 $|p_0 - p_2| = |2 - 1| = 1 = p_2$。

小青鱼希望你设计一种策略来找出这个排列。当然,小青鱼不想让你太容易赢得游戏。因此,他会自适应地(adaptively)改变排列 $p$ 来诱骗你(详情请参阅“交互”部分)。

输入格式

每个测试点包含多个测试用例。输入的第一行包含一个整数 $T$($1 \le T \le 100$),表示测试用例的数量。

对于每个测试用例,输入的第一行包含一个整数 $n$($1 \le n \le 1000$)。随后,交互开始。

交互

要进行询问,请按以下格式输出一行:

? i j

其中 $i$ 和 $j$ 是 $0$ 到 $n$ 之间的两个整数。你必须确保询问次数不超过 $1024$ 次。作为对询问的响应,你将获得一个整数 $k$,满足 $p_k = |p_i - p_j|$。

要报告答案,请按以下格式输出一行:

! p0 p1 ... pn

其中 $p$ 是你希望报告的排列。

在输出询问或报告答案后,请不要忘记输出换行符并清空输出流。

在本题中,交互器是自适应的。这意味着排列 $p$ 可能会根据你的询问而改变,只要它与你之前提出的询问不矛盾即可。

样例

输入格式 1

1
3
1
3

输出格式 1

? 2 2
? 0 3
! 2 0 3 1

说明

测试工具:我们提供了一个测试工具以帮助参赛者开发和测试他们的解决方案。你可以从附件中下载该工具。使用 -h 参数运行该工具可以查看其使用说明。该测试工具仅实现部分测试场景以及真实评测程序的部分功能。

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.