QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 1024 MB Puntuación total: 100 Interactivo

#8939. 排列

Estadísticas

这是一个交互式问题。

有一个长度为 $n$ 的未知排列。你需要确定数字 $n$ 在该排列中的位置。

为了做到这一点,你可以进行以下询问:

  • 选择一个区间 $[l, r]$ ($l < r$),询问区间 $[l, r]$ 中第二大数字的位置。

你需要在不超过 $1.5 \log_2 n$ 次询问内确定数字 $n$ 的位置。此外,由于我们的交互器效率有限,它只能在 $\Theta(r - l)$ 的时间内找到区间内的第二大数字,因此你所有询问的 $r - l + 1$ 之和不应超过 $3n$。

在本题中,交互器是非自适应的。也就是说,排列在所有询问开始前就已经固定。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 10000$),表示测试用例的数量。

对于每个测试用例,第一行包含一个整数 $n$ ($2 \le n \le 10^6$),表示排列的长度。保证所有测试用例的 $n$ 之和不超过 $10^6$。

交互

进行询问时,输出一行格式为 “? $l$ $r$” ($1 \le l < r \le n$) 的内容。然后你应该从标准输入读取响应。

报告答案时,输出一行格式为 “! $x$” 的内容,表示数字 $n$ 的位置为 $x$。

输出答案后,你的程序应处理下一个测试用例,或者在没有更多测试用例时终止。

输出每一行后,请务必输出换行符并刷新缓冲区。在 C++ 中,可以使用 fflush(stdout)cout.flush();在 Java 中,可以使用 System.out.flush();在 Python 中,可以使用 stdout.flush()

样例

输入 1

2
5
3
3
3
2
2

输出 1

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

说明

请注意,样例仅用于展示交互过程的正确格式,并不保证在这些交互之后一定能得到确定的结果。

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.