QOJ.ac

QOJ

Time Limit: 3.0 s Memory Limit: 512 MB Total points: 100 Interactive Hackable ✓

#7535. 受限洗牌还原

Statistics

这是一个交互式问题。

Bobo 拥有一个初始为 $(1, 2, \dots, n)$ 的数组 $a$。他对数组进行了以下操作:

  • 对于从 $1$ 到 $n$ 的每个 $i$,Bobo 选择一个满足 $i \le j \le \min(n, i + 2)$ 的下标 $j$,并交换 $a_i$ 和 $a_j$。当然,如果 $i = j$,则操作后什么都不会发生。

你的目标是确定最终的数组。你可以询问以下类型的问题:

  • ? i j 表示询问 “$a_i$ 和 $a_j$ 的大小关系如何?”。Bobo 将回复一个符号 <>,分别表示 $a_i < a_j$ 或 $a_i > a_j$。

你最多可以询问 $\lfloor 5n/3 \rfloor + 5$ 次问题。在此之后,你必须猜出该数组。

交互格式

首先,交互器会在单独的一行中打印数字 $n$ ($1 \le n \le 30\,000$)。然后,程序进行询问,每个询问由单独一行上的 ? i j 组成,其中 $1 \le i, j \le n$ 且 $i \neq j$。

每次询问后,交互器会在单独的一行中打印一个字符 <>

在程序完成询问后,必须做出猜测。如果你认为数组是 $(a_1, \dots, a_n)$,请在单独的一行中打印 ! a_1 a_2 ... a_n 并终止程序。

如果你的程序询问次数超过 $\lfloor 5n/3 \rfloor + 5$ 次,交互器将给出 WA 判决。如果你在打印询问后没有刷新输出,可能会收到 IL 判决。

注意,本题中的交互器是自适应的,即数组可能会在运行时根据你的询问动态生成。

样例

输入 1

5
<
>
>
<
>
>

输出 1

? 5 4
? 5 1
? 5 3
? 3 1
? 2 1
? 5 2
! 2 3 1 5 4

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.