QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100 Interactive Hackable ✓

#18515. 遊戲:游標最小值

Statistics

這是一個互動式問題。

一個長度為 $n=30000$ 的排列 $p$ 隱藏在裁判中。你的任務是找出此排列中最小值的索引。

裁判是非適應性的:排列在互動開始前就已選定,且絕不會改變。

與一般的比較查詢不同,裁判只將你當前的查詢與上一次的查詢進行比較。更精確地說,若你上一次查詢的索引為 $i$,而現在查詢索引 $j$,裁判會告訴你 $p_i$ 與 $p_j$ 的比較結果。

你最多可以進行 $q_{\max}=42000$ 次查詢。

官方評測資料由 100 個獨立的測試檔組成。你的程式會在每個檔案上獨立執行。

互動

互動一開始,你的程式必須讀入兩個整數

$$ n \quad q_{\max}. $$

在官方測試中,$n=30000$ 且 $q_{\max}=42000$。

若要進行查詢,請依據以下格式輸出一行:

$$ \text{? j} $$

其中 $1 \le j \le n$。

裁判會回應一個字元:

  • < 如果 $p_i < p_j$,其中 $i$ 是上一次的查詢索引(如果適用的話);
  • = 如果這是第一次查詢,或者 $p_i=p_j$;
  • > 如果 $p_i > p_j$,其中 $i$ 是上一次的查詢索引(如果適用的話)。

由於 $p$ 是一個排列,第一次查詢之後只有在查詢與上一次相同的索引時才會收到 =

如果裁判回應 -1,你的程式必須立即終止。這表示你的程式違反了互動協議,將會得到 Wrong Answer。

若要輸出最終答案,請依據以下格式輸出一行:

$$ \text{! a} $$

其中 $a$ 是你認為包含最小值的索引。輸出答案後,你的程式必須終止。最終答案不計入查詢次數。

若你的程式超過 $q_{\max}$ 次查詢、查詢無效索引、輸出無效指令或輸出錯誤的最終答案,則會得到 Wrong Answer。

每次輸出查詢或答案後,請清空輸出緩衝區。例如,在 C++ 中可以使用 endlcout.flush()

說明

此範例僅為互動過程的示例,不會出現在實際測試資料中。形式為 (receiving ... output) 的行是僅用於在範例中對齊查詢與裁判回覆的佔位符。在實際測試案例中,裁判不會輸出這些佔位行,參賽者不應讀取或列印它們。

在此範例互動中,隱藏的排列為 $p=(3,1,4,2)$。以下項目符號描述了範例中顯示的互動過程。

  • 裁判首先發送 $n=4$ 與查詢限制 $5$。
  • 第一次查詢 ? 1 收到 =,因為沒有上一次查詢的索引。
  • 查詢 ? 2 比較 $p_1=3$ 與 $p_2=1$,因此裁判回應 >
  • 查詢 ? 4 比較 $p_2=1$ 與 $p_4=2$,因此裁判回應 <。最小值在索引 $2$,所以 ! 2 是正確的。

本地互動工具: 附加的 attachments/local_interactive.py 可以使用 --perm 3,1,4,2 --limit 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.