题目描述
This is an interactive problem.
There is a hidden permutation p1,p2,…,pn of {1,2,…,n}. You want to find it by asking the parity of the number of inversions of pl,…,pr.
You can query in the format ? l r, and the interactor will respond you (∑l≤i<j≤r[pi>pj])mod2. [pi>pj] is 1 when pi>pj and 0 when pi≤pj.
输入格式
Firstly, you should read the integer n (1≤n≤2000).
After that, you can make no more than 4×104 queries. To make a query, output ``? l r'' (1≤l≤r≤n) on a separate line, then you should read the response from standard input.
To give your answer, print ``! p1 p2 … pn'' on a separate line. The output of the answer is \textbf{not} counted towards the limit of 4×104 queries.
After that, your program should terminate.
After printing a query, do not forget to output end of line and flush the output. To do this, use fflush(stdout) or cout.flush() in C++, System.out.flush() in Java, flush(output) in Pascal, or stdout.flush() in Python.
It is guaranteed that the permutation is fixed in advance.
题目大意
【题目描述】
这是一个交互式问题。
有一个隐藏的排列 p1,p2,…,pn,其中包含 {1,2,…,n} 的排列。你想通过询问 pl,…,pr 的逆序对数量的奇偶性来找到它。
你可以以 ? l r 的格式进行查询,交互器会回答你 (∑l≤i<j≤r[pi>pj])mod2。其中 [pi>pj] 在 pi>pj 时为 1,在 pi≤pj 时为 0。
首先,你需要读入整数 n(1≤n≤2000)。
之后,你可以进行不超过 4×104 次查询。要进行查询,输出 ? l r(1≤l≤r≤n)在单独的一行上,然后你应该从标准输入中读取响应。
要给出你的答案,将 ! p1 p2 … pn 打印在单独的一行上。答案的输出 不 计入 4×104 次查询的限制。
之后,你的程序应该终止。
在打印查询后,不要忘记输出换行并刷新输出。要做到这一点,在 C++ 中使用 fflush(stdout) 或 cout.flush(),在 Java 中使用 System.out.flush(),在 Pascal 中使用 flush(output),或者在 Python 中使用 stdout.flush()。
保证排列提前固定。
翻译来自于:ChatGPT