#P10159. [DTCPC 2024] The last permutation

    ID: 11518 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2024交互题Special Judge剪枝构造洛谷月赛

[DTCPC 2024] The last permutation

Background

The background of this problem is not entirely fictional and does not imply anything about any real person..

Xiao L was the “white moonlight” (baiyueguang) of Xiao L in middle school.

One day, Xiao L said on Moments that they wanted to play “Nong”, and Xiao L quickly studied how to download Honor of Kings.

The next day, Xiao L said on Moments that they wanted to play PUBG, and Xiao L quickly studied how to download PUBG.

But Xiao L soon broke up with Xiao L. Xiao L’s last feelings turned into a permutation. Unfortunately, Xiao L was not willing to tell everyone.

However, after your constant questioning, Xiao L finally agreed to answer a few questions about the permutation.

Problem Description

There is a hidden permutation pp of length nn. You may perform the following queries any number of times: choose a triple (l,r,k)(l, r, k) satisfying 1lrn1 \le l \le r \le n, 1krl+11 \le k \le r - l + 1. The interactive judge will return the kk-th largest value among indices in [l,r][l, r].

For one query, the cost is 1rl+1\frac{1}{r - l + 1}. You need to determine the permutation within a total cost not exceeding 11.811.8.

The interactive judge is non-adaptive. That is, the permutation you need to find is already fixed before the interaction starts.

Input Format

The first line contains a positive integer tt (1t51 \le t \le 5), the number of test cases.

For each test case, one line contains nn (1n10001 \le n \le 1000), the length of the permutation pp.

When you have determined the permutation, you should output in the form ! p1 p2 ... pn to indicate the permutation you found.

This problem uses IO interactive mode.

Interaction Format

  • ? l r k: query the kk-th largest value among indices in [l,r][l, r].

  • ! p1 p2 p3 ... pn: output the answer.

Please note: in each test case, ensure that the total cost of all queries does not exceed 11.811.8.

Also note that after each operation, you need to call the following function to flush the output buffer:

  • For C/C++: fflush(stdout);
  • For C++: std::cout << std::flush;
  • For Java: System.out.flush();
  • For Python: stdout.flush();
  • For Pascal: flush(output);

For other languages, please refer to the corresponding language documentation.

Output Format

See “Interaction Format”.

1
5

2

3

1

4




? 1 1 1

? 2 2 1

? 3 3 1

? 4 4 1

! 2 3 1 4 5

Hint

Translated by ChatGPT 5