luogu#P7971. [KSN2021] Colouring Balls
[KSN2021] Colouring Balls
Problem Description
This is an interactive problem.
There are balls, numbered from to .
Each time, you may ask how many different colors appear among the balls whose indices are in . You need to determine the color of every ball. Since you do not know what the actual colors are, you only need to use the same number to represent the same color.
Input Format
See “Interaction Format”.
Output Format
See “Interaction Format”.
1
5 10000
2
1
2
? 1 5
? 1 3
? 2 4
! 1 1 1 2 2
Hint
Constraints
This problem uses bundled testdata.
- Subtask 1 (8 points): , it is guaranteed that the indices of balls of each color form a contiguous segment.
- Subtask 2 (7 points): , it is guaranteed that the indices of balls of each color form a contiguous segment.
- Subtask 3 (19 points): , it is guaranteed that there are at most colors in total.
- Subtask 4 (14 points): , it is guaranteed that there are at most colors in total.
- Subtask 5 (12 points): , it is guaranteed that there are at least colors in total.
- Subtask 6 (21 points): , it is guaranteed that .
- Subtask 7 (19 points): .
For all testdata, it is guaranteed that and .
Input Format
See “Interaction Format”.
Output Format
See “Interaction Format”.
Hint
Interaction Format
The first line contains a positive integer , which represents the Subtask ID (not the number of test cases).
The second line contains two integers , representing the number of balls and the query limit.
Next, you may make at most queries and read the answers returned by the interactor. Each query should be in the format ? l r, meaning you ask for the number of colors among the balls in .
When you are sure about the colors of all balls, you should output ! a1 a2 ... an to represent the colors of all balls. You must ensure that:
- and all are integers.
- Balls with the same color have the same .
- Balls with different colors have different .
After each output, you must flush the buffer. You may use the following statements to flush:
- 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 documentation for the corresponding language.
Translated by ChatGPT 5