QOJ.ac

QOJ

時間限制: 2.0 s 記憶體限制: 256 MB 總分: 100

#18543. Small Numbers Search

统计

这是一个交互式问题。

裁判有一个由 $1$ 到 $n$ 的数字组成的排列。你的任务是找出数字 $1$ 到 $k$ 所在的位置。为此,你可以使用裁判的程序,该程序可以比较排列中任意两个位置的数字大小。

输入格式

输入的第一行包含两个整数 $n$ 和 $k$:排列的大小以及需要寻找的位置数量。在除样例外的所有测试点中,满足 $n = 10\,000$ 且 $k \le 10$。

接下来是针对你的询问的回答,每行一个。如果进行比较的两个数字中,第一个数字小于第二个数字,该行将包含一个字符 <;否则,将包含一个字符 >

输出格式

如果你想比较位置 $i$ 和 $j$ 处的数字,你必须输出一行 ? i j。这里,$i$ 和 $j$ 必须是 $1$ 到 $n$ 之间不同的整数。你最多可以进行 $10\,700$ 次比较询问。

如果你找到了所有 $1$ 到 $k$ 的数字所在的位置,输出 ! pos1 pos2 ... posk,然后终止你的程序。

为了防止输出缓冲,在输出每行后,请务必执行刷新缓冲区的操作。例如,在 C 或 C++ 中可以使用 fflush(stdout),在 Java 中可以使用 System.out.flush(),在 Pascal 中可以使用 flush(output),在 Python 中可以使用 sys.stdout.flush()

此外,不要忘记在输出的每一行末尾加上换行符。

样例

输入样例 1

3 3
<
>
<

输出样例 1

? 1 2
? 3 1
? 2 3
! 1 2 3

说明

在样例中,裁判的排列为 $1\ 2\ 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.