luogu#P9721. [EC Final 2022] Inversion

[EC Final 2022] Inversion

题目描述

This is an interactive problem.\textbf{This is an interactive problem.}

There is a hidden permutation p1,p2,,pnp_1, p_2, \dots, p_n of {1,2,,n}\{1, 2, \dots, n\}. You want to find it by asking the parity of the number of inversions of pl,,prp_l,\ldots, p_r.

You can query in the format ? l r{?~l~r}, and the interactor will respond you $\left( \sum_{l\leq i < j\leq r} [p_i > p_j]\right) \bmod 2$. [pi>pj][p_i>p_j] is 11 when pi>pjp_i>p_j and 00 when pipjp_i\le p_j.

输入格式

Firstly, you should read the integer nn (1n20001\le n\le 2000).

After that, you can make no more than 4×1044 \times 10^4 queries. To make a query, output ``? l r{?~l~r}'' (1lrn1 \leq l \leq r \leq n) on a separate line, then you should read the response from standard input.

To give your answer, print ``! p1 p2  pn{!~p_1~p_2~\dots~p_n}'' on a separate line. The output of the answer is \textbf{not} counted towards the limit of 4×1044 \times 10^4 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)\texttt{fflush(stdout)} or cout.flush()\texttt{cout.flush()} in C++, System.out.flush()\texttt{System.out.flush()} in Java, flush(output)\texttt{flush(output)} in Pascal, or stdout.flush()\texttt{stdout.flush()} in Python.

It is guaranteed that the permutation is fixed in advance.

题目大意

【题目描述】

这是一个交互式问题。

有一个隐藏的排列 p1,p2,,pnp_1, p_2, \dots, p_n,其中包含 {1,2,,n}\{1, 2, \dots, n\} 的排列。你想通过询问 pl,,prp_l,\ldots, p_r 的逆序对数量的奇偶性来找到它。

你可以以 ? l r{?~l~r} 的格式进行查询,交互器会回答你 $\left( \sum_{l\leq i < j\leq r} [p_i > p_j]\right) \bmod 2$。其中 [pi>pj][p_i>p_j]pi>pjp_i>p_j 时为 11,在 pipjp_i\le p_j 时为 00

首先,你需要读入整数 nn1n20001\le n\le 2000)。

之后,你可以进行不超过 4×1044 \times 10^4 次查询。要进行查询,输出 ? l r{?~l~r}1lrn1 \leq l \leq r \leq n)在单独的一行上,然后你应该从标准输入中读取响应。

要给出你的答案,将 ! p1 p2  pn{!~p_1~p_2~\dots~p_n} 打印在单独的一行上。答案的输出 \textbf{不} 计入 4×1044 \times 10^4 次查询的限制。

之后,你的程序应该终止。

在打印查询后,不要忘记输出换行并刷新输出。要做到这一点,在 C++ 中使用 fflush(stdout)\texttt{fflush(stdout)}cout.flush()\texttt{cout.flush()},在 Java 中使用 System.out.flush()\texttt{System.out.flush()},在 Pascal 中使用 flush(output)\texttt{flush(output)},或者在 Python 中使用 stdout.flush()\texttt{stdout.flush()}

保证排列提前固定。

翻译来自于:ChatGPT

3

0

0

1


? 1 2

? 1 3

? 2 3

! 2 3 1