luogu#P8320. 『JROI-4』Sunset
『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 (meaning the number of interactions) (sure) — note from the reviewer.
Problem Description
This is an interactive problem.
Sunset can be abstracted as a sequence .
is a permutation of .
You also have a sequence , which is the prefix maximum of the current sequence.
In other words,
Note: According to the definition above, may change as the sequence changes.
You can perform two different operations:
- Specify an , and ask: for the current sequence, how many distinct values are there in .
- Specify an , and set .
Please determine the original permutation using no more than operations.
It is guaranteed that the interactive library is static, i.e. the interactive library will not change the sequence during the interaction.
Input Format
This problem has multiple test cases. The first line contains an integer , the number of test cases. Then follow lines, each containing an integer , the length of the sequence in this test case.
This problem uses IO interaction mode.
Interaction Format
-
? 1 iQuery how many distinct values there are in . The interactive library returns a positive integer as the answer. -
? 2 iSet . -
! a1 a2 a3 ... anOutput the answer.
Note: In each test case, please make sure the total number of the first two types of operations does not exceed .
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 is 1 2 3, and is 1 2 3.
After outputting a command like ? 2 2 to the interactive library, the sequence becomes 1 0 3, and becomes 1 1 3. At this time, there are distinct values in , namely .
Reference materials for contestants: OI Wiki - Interactive Problems | Guess Number (IO Interactive Version)
Constraints
- For of the testdata, .
- For of the testdata, .
- For another of the testdata, the sequence is generated randomly.
- For all testdata: .
Translated by ChatGPT 5