#P9918. 「RiOI-03」Just a Q. (Hard ver.)

    ID: 10613 远端评测题 1800ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学二分洛谷原创交互题Special JudgeO2优化洛谷月赛Ad-hoc

「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 900900 ms and a memory limit of 3232 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 QQ. Initially, Q=0Q = 0.

Little R has nn hidden integers q1qnq_1 \dots q_n, satisfying 1qiV1 \leq \lvert q_i \rvert \leq V, and there exists exactly one index ii such that qi<0q_i \lt 0. You need to find this index ii with qi<0q_i \lt 0.

Little R promises she will not make you blindly guess with only a 1n\frac{1}{n} chance, so she allows you to make at most kk queries. In each query, you may give Little R a multiset SS of positive integers, satisfying 0SSmax0 \leq \lvert S \rvert \leq S_{\max} and iS,in\forall i \in S, i \leq n. She will compute M=iSqiM = \prod\limits_{i\in S}q_i, and then update QQ+MQ \leftarrow Q + M. In particular, if SS is empty, then M=1M = 1.

After a query, Little R will tell you the current sgn(Q)\text{sgn}(Q) (one of +, -, or 0), which is the sign of QQ. Specifically, if Q>0Q \gt 0, Little R returns +; if Q<0Q \lt 0, she returns -; otherwise she returns 0.

You must find the index ii with qi<0q_i \lt 0 using no more than kk queries.

It is guaranteed that for all testdata, the index ii such that qi<0q_i \lt 0 is chosen uniformly at random from [1,n][1, n]. Note that reporting an index counts as one query.

Input Format

Interactive format

In the first line, read three positive integers n,k,Smaxn, k, S_{\max}.

After that, you should make some queries.

For each query, output ? m s1 s2sm?\ m\ s_1\ s_2 \dots s_m, meaning you provide a multiset SS of positive integers of size mm. You must ensure 0mSmax0 \leq m \leq S_{\max}. Also, you must have 1sin1 \leq s_i \leq n, describing the indices of the elements in the multiset.

If you have obtained the answer, output ! i!\ i, where 1in1 \leq i \leq n, meaning you conclude qi<0q_i \lt 0. 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 sgn(Q)\text{sgn}(Q).

Input format

This problem has multiple test cases.

The first line contains an integer TT, 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 n,k,Smaxn, k, S_{\max} 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

q={1,1,4,5,1,4}q = \{-1, 1, 4, 5, 1, 4\}.

Constraints and conventions

This problem uses bundled tests.

Subtask ID nn \leq TT \leq k=k = Smax=S_{\max} = Score
00 200200 500500 2020 20n+120n + 1 1111
11 10001000 5050 4141 8n+108n + 10 2525
22 5050 6n+106n + 10 3030
33 10410^4 1010 3939 1.5n+10\lceil 1.5n\rceil + 10 3434

For subtasks 0,1,30, 1, 3, if you pass all test points you get the full score; otherwise you get 00 points.

For subtask 22:

  • You need to ensure that the actual number of operations you use, kk', satisfies 0k500 \leq k' \leq 50.
  • You need to ensure that the actual number of operations you use, SS', satisfies 0S6n+100 \leq S' \leq 6n + 10.
  • 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, 1V1061 \leq V \leq 10^6, 1n1041 \leq n \leq 10^4, 1T5001 \leq T \leq 500. Note that due to interactor limitations, n,T\bm{n, T} will not both take their maximum values at the same time. Also, the values of kk and SmaxS_{\max} for each subtask are already given.

Translated by ChatGPT 5