CF1491F.Magnets

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is an interactive problem.

Kochiya Sanae is playing with magnets. Realizing that some of those magnets are demagnetized, she is curious to find them out.

There are nn magnets, which can be of the following 33 types:

  • N
  • S
    • — these magnets are demagnetized.

Note that you don't know the types of these magnets beforehand.

You have a machine which can measure the force between the magnets, and you can use it at most n+log2nn+\lfloor \log_2n\rfloor times.

You can put some magnets to the left part of the machine and some to the right part of the machine, and launch the machine. Obviously, you can put one magnet to at most one side (you don't have to put all magnets). You can put the same magnet in different queries.

Then the machine will tell the force these magnets produce. Formally, let n1,s1n_1,s_1 be the number of N and S magnets correspondently on the left and n2,s2n_2,s_2 — on the right. Then the force between them would be n1n2+s1s2n1s2n2s1n_1n_2+s_1s_2-n_1s_2-n_2s_1 . Please note that the force is a signed value.

However, when the absolute value of the force is strictly larger than nn , the machine will crash into pieces.

You need to find all magnets of type - (all demagnetized ones), without breaking the machine.

Note that the interactor is not adaptive. The types of the magnets are fixed before the start of the interaction and do not change with queries.

It is guaranteed that there are at least 22 magnets whose type is not -, and at least 11 magnet of type -.

输入格式

The first line contains a single integer tt ( 1t1001 \leq t \leq 100 ) — the number of test cases.

输出格式

For each test case you should start by reading an integer nn ( 3n20003 \leq n \leq 2000 ) — the number of the magnets.

It is guaranteed that the total sum of all nn over all test cases doesn't exceed 20002000 .

After that you can put some magnets into the machine and make a query from the statement.

You have to print each query in three lines:

  • In the first line print "? l r" (without quotes) where ll and rr ( 1l,r<n1 \leq l,r < n , l+rnl+r \leq n ) respectively denote the number of the magnets you put to left and right.
  • In the second line print ll integers a1,,ala_1, \dots, a_l ( 1ain1 \leq a_i \leq n , aiaja_i \neq a_j if iji \neq j ) — the indices of the magnets you put to left.
  • In the third line print rr integers b1,,brb_1, \dots, b_r ( 1bin1 \leq b_i \leq n , bibjb_i \neq b_j if iji \neq j ) — the indices of the magnets you put to right.
  • The same magnet can't be put to both sides in the same query. Formally, you should guarantee that aibja_i \neq b_j for any ii and jj . However, you may leave some magnets unused.

After printing a query do not forget to output end of line and flush the output. To do this, use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see documentation for other languages.

After this, you should read an integer FF — the force these magnets produce.

Note that if your query is invalid(either the query limit exceeds, the machine crashes or the arguments are invalid), the interactor will terminate immediately. In this case terminate your program to receive verdict Wrong Answer instead of arbitrary verdicts.

If you are confident about your answer, use the following format to report it:

  • "! k A", where kk is the number of magnets you found, and AA is an array consisting of kk different integers from 11 to nn denoting the indices of the magnets of type - that you found. You may print elements of AA in arbitrary order.
  • After that, if this is the last test case, you have to terminate your program; otherwise you should immediately continue to deal with the next test case.

Note that the interactor is not adaptive. The types of the magnets are fixed before the start of interaction and do not change with queries.

Hacks

To hack a solution, use the following format:

The first line contains a single integer tt ( 1t1001 \leq t \leq 100 ) — the number of test cases in your hack.

Then follow the descriptions of the tt test cases, each printed in two lines:

  • The first line contains a single integer nn ( 3n20003 \leq n \leq 2000 ) — the number of magnets.
  • The second line contains a string SS of length nn consisting of only N, S and -, denoting the magnets' types.
  • Each of your test case should guarantee that there are at least 22 magnets whose type is not -, and at least 11 magnet of type -. Meanwhile, the total sum of nn in all test cases should not exceed 20002000 .

输入输出样例

  • 输入#1

    1
    4
    
    
    
    0
    
    
    
    1
    
    
    
    0
    
    
    
    0

    输出#1

    ? 1 1
    3
    4
    
    ? 1 2
    1
    2 3
    
    ? 1 1
    1
    4
    
    ? 1 1
    1
    3
    
    ! 2 3 4

说明/提示

The empty lines in the sample are just for you to better understand the interaction process. You're not required to print them.

In the sample, the types of the magnets are NN--.

At first, you put the third magnet on the left and the fourth one on the right. Both of them have type -, thus no force is produced.

Then you put the first magnet on the left and the second and third one on the right. The third magnet has type -, while the other two magnets are of type N, so the force produced is 11 .

In the following two queries, the force is 00 since there is only a magnet with property - on the right.

Then we can determine that the magnets of type - are the third and the fourth one, so we should print ! 2 3 4 and exit.

首页