luogu#P8320. 『JROI-4』Sunset

    ID: 7279 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>洛谷原创交互题Special Judge洛谷月赛

『JROI-4』Sunset

Background

I cannot write nice text, so I will simply not include a background. [Background to be filled.]

Since this is only a C-level problem, the setter decided to be a bit more kind, so they added a few 00 (meaning the number of interactions) (sure) — note from the reviewer.

Problem Description

This is an interactive problem.

Sunset can be abstracted as a sequence {an}\{a_n\}.

{an}\{a_n\} is a permutation of 1n1 \sim n.

You also have a sequence {dn}\{d_n\}, which is the prefix maximum of the current aa sequence.

In other words,

di=maxj=1i{aj}d_i=\max_{j=1}^i \{a_j\}

Note: According to the definition above, {dn}\{d_n\} may change as the sequence {an}\{a_n\} changes.

You can perform two different operations:

  • Specify an ii, and ask: for the current aa sequence, how many distinct values are there in d1id_{1\sim i}.
  • Specify an ii, and set ai0a_i\leftarrow 0.

Please determine the original permutation using no more than 55005500 operations.

It is guaranteed that the interactive library is static, i.e. the interactive library will not change the aa sequence during the interaction.

Input Format

This problem has multiple test cases. The first line contains an integer TT, the number of test cases. Then follow TT lines, each containing an integer nn, the length of the sequence in this test case.

This problem uses IO interaction mode.

Interaction Format

  • ? 1 i Query how many distinct values there are in d1id_{1\sim i}. The interactive library returns a positive integer xx as the answer.

  • ? 2 i Set ai=0a_i=0.

  • ! a1 a2 a3 ... an Output the answer.

Note: In each test case, please make sure the total number of the first two types of operations does not exceed 55005500.

Also note that after each operation, you need to call the following function to flush the 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 check the corresponding language documentation.

Output Format

See “Interaction Format”.

1

3

1

2

3


2





? 1 1

? 1 2

? 1 3

? 2 2
? 1 3

! 1 2 3

Hint

The sample is only for understanding the interaction process and may not be logically consistent.

[Sample Explanation]

The initial sequence aa is 1 2 3, and dd is 1 2 3.

After outputting a command like ? 2 2 to the interactive library, the sequence aa becomes 1 0 3, and dd becomes 1 1 3. At this time, there are 22 distinct values in d1d3d_1\sim d_3, namely 1,31,3.


Reference materials for contestants: OI Wiki - Interactive Problems | Guess Number (IO Interactive Version)


Constraints

  • For 10%10\% of the testdata, T=1T=1.
  • For 30%30\% of the testdata, n70n\le 70.
  • For another 20%20\% of the testdata, the sequence aa is generated randomly.
  • For all testdata: T10,1n500T \leq 10,1\leq n\leq 500.

Translated by ChatGPT 5