#P9918. 「RiOI-03」Just a Q. (Hard ver.)
「RiOI-03」Just a Q. (Hard ver.)
Background
"Yes, I am Q."
Little R smiles slightly.
- It is guaranteed that any reasonable partial-score or full-score solution with std + spj for this problem can run correctly under the current testdata within a time limit of ms and a memory limit of MB, and get AC.
- This problem will not add hack data that is only meant to meaninglessly max out the spj running time.
Note that only the Constraints differ from the normal version, and the Constraints of the two versions do not completely overlap.
Problem Description
This is an interactive problem.
Little R has a variable . Initially, .
Little R has hidden integers , satisfying , and there exists exactly one index such that . You need to find this index with .
Little R promises she will not make you blindly guess with only a chance, so she allows you to make at most queries. In each query, you may give Little R a multiset of positive integers, satisfying and . She will compute , and then update . In particular, if is empty, then .
After a query, Little R will tell you the current (one of +, -, or 0), which is the sign of . Specifically, if , Little R returns +; if , she returns -; otherwise she returns 0.
You must find the index with using no more than queries.
It is guaranteed that for all testdata, the index such that is chosen uniformly at random from . Note that reporting an index counts as one query.
Input Format
Interactive format
In the first line, read three positive integers .
After that, you should make some queries.
For each query, output , meaning you provide a multiset of positive integers of size . You must ensure . Also, you must have , describing the indices of the elements in the multiset.
If you have obtained the answer, output , where , meaning you conclude . After that, you should immediately exit the current interaction.
After each output, flush the buffer.
You may use the following statements 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 documentation of the corresponding language.
In particular, for C++, if you use std::endl instead of '\n' when outputting a newline, it will also flush the buffer automatically.
After each query and flushing the buffer, you will read one character from standard input, which is +, -, or 0, representing the current sign .
Input format
This problem has multiple test cases.
The first line contains an integer , indicating the number of test cases.
For each test case, please interact according to [Interactive format]. After you report an index:
- If the index you give is correct:
- If this is the last test case, the interactor exits and returns Accepted.
- If this is not the last test case, you should continue to read to start interacting for the next test case.
- Otherwise, if the index is incorrect, the interactor will terminate immediately and return Unaccepted.
Output Format
See [Input Format].
1
6 6 6
-
-
-
+
0
? 1 1
? 5 1 2 3 4 5
? 3 2 4 6
? 1 4
? 3 1 5 6
! 1
Hint
Sample explanation 1
.
Constraints and conventions
This problem uses bundled tests.
| Subtask ID | Score | ||||
|---|---|---|---|---|---|
For subtasks , if you pass all test points you get the full score; otherwise you get points.
For subtask :
- You need to ensure that the actual number of operations you use, , satisfies .
- You need to ensure that the actual number of operations you use, , satisfies .
- The score for a single test point is $\left(1 - \max(\frac{\max k' - 35}{20}, \max(\frac{S' - 3n - 10}{4n + 1}), 0)\right)\times 30$.
- The subtask score is the minimum score among all test points.
For all testdata, , , . Note that due to interactor limitations, will not both take their maximum values at the same time. Also, the values of and for each subtask are already given.
Translated by ChatGPT 5