#P10887. 【MX-S3-T3】「FeOI Round 1」再演

    ID: 10712 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>交互题Special JudgeO2优化梦熊比赛

【MX-S3-T3】「FeOI Round 1」再演

Background

Original problem link: https://oier.team/problems/S3C


Problem Description

This is an interactive problem.

jt has a set SS of size nn. Each element in the set is an unordered integer pair (x,y)(x, y). It is guaranteed that among the 2n2n integers from 11 to 2n2n, each appears exactly once in the set.

For example, when n=3n = 3, a valid set SS could be {(1,5),(2,3),(4,6)}\{(1, 5), (2, 3), (4, 6)\}.

At the beginning, you only know nn, but you do not know what SS is.

Now one kind of operation is supported: you can give i,ji, j (1i,j2n1 \le i, j \le 2n), then jt will swap the positions of ii and jj in SS (if i,ji, j are in the same pair, or i=ji = j, then nothing happens).

For example, when S={(1,5),(2,3),(4,6)}S = \{(1, 5), (2, 3), (4, 6)\}, after performing i=2,j=6i = 2, j = 6, we have $S = \{(1, 5), (6, 3), (4, 2)\} = \{(1, 5), (2, 4), (3, 6)\}$.

At the very beginning and after each operation, for the current set SS, jt will tell you

res=min(x,y)Smax(x,y).res = \min\limits_{(x, y) \in S} \max(x, y).

For example, when S={(1,5),(2,3),(4,6)}S = \{(1, 5), (2, 3), (4, 6)\}, we have $res = \min(\max(1, 5), \max(2, 3), \max(4, 6)) = \min(5, 3, 6) = 3$.

Note that after jt tells you resres each time, jt will not undo the operations you made, i.e. your operations remain effective.

You need to guess the initial set SS within limlim operations, i.e. the version before any swap operations.

It is guaranteed that the initial SS is fixed in advance, i.e. the interactor is not adaptive.

Interaction

This problem contains multiple test cases in a single test file.

First read the number of test cases TT.

Then there are TT test cases. For each test case, do the following process:

Input the size nn of SS and limlim to start the interaction.

For each operation, first read resres, then output one line ^ i j to indicate that you want to perform the operation on i,ji, j.

After you have determined the answer, first output one line containing a single !, then output nn lines, each with two integers x y representing one pair in SS, and then get ready to read the next test case. You may output these pairs in any order, and the order inside each pair can also be arbitrary.

After each line you output, please flush the buffer:

  • In C++, use fflush(stdout) or cout.flush().
  • In Pascal, use flush(output).
  • In Python, use stdout.flush().
  • For other languages, please check the documentation yourself.

When the total number of operations over all testdata in a single test point does not exceed 2.5×105\boldsymbol{2.5 \times 10^5}, it is guaranteed that the interactor runs within 1s1\operatorname s time and 128MB128\operatorname{MB} memory. That is, you can use at least 1s1 \operatorname{s} of time and 384MB384\operatorname{MB} of memory.

Input Format

See "Interaction".

Output Format

See "Interaction".

2
3 100
3

3

4

2




1 0
2



^ 1 2

^ 3 6

^ 6 2

!
5 1
6 4
2 3


!
1 2

Hint

Sample Explanation

Note that the sample only describes one possible interaction process, and it may not be logically consistent (that is, the answer might be a random guess that happens to be correct).

For the first test case, initially S={(1,5),(2,3),(4,6)}S = \{(1, 5), (2, 3), (4, 6)\}, and jt tells you res=3res = 3.

Then you swap 1,21, 2, SS becomes {(2,5),(1,3),(4,6)}\{(2, 5), (1, 3), (4, 6)\}, and jt tells you res=3res = 3.

Then you swap 3,63, 6, SS becomes {(2,5),(1,6),(3,4)}\{(2, 5), (1, 6), (3, 4)\}, and jt tells you res=4res = 4.

Then you swap 6,26, 2, SS becomes {(5,6),(1,2),(3,4)}\{(5, 6), (1, 2), (3, 4)\}, and jt tells you res=2res = 2.

You output {(5,1),(6,4),(2,3)}\{(5, 1), (6, 4), (2, 3)\}. You used 33 operations, which does not exceed lim=100lim = 100, so the answer is correct.

For the second test case, initially S={(1,2)}S = \{(1, 2)\}. You directly output {(1,2)}\{(1, 2)\}. You used 00 operations, which does not exceed lim=0lim = 0, so the answer is correct.

Constraints

This problem uses bundled tests.

Let n\sum n be the sum of all nn within a single test point.

For 100%100\% of the data, 1T1051 \le T \le 10^5, 1n5×104 1 \le n \le 5 \times 10^4, n105 \sum n \le 10^5.

Subtask ID TT nn limlim Score
11 =1=1 =0=0 11
ii (2i62 \le i \le 6) =(2i1)!!=(2i-1)!! =i=i =109=10^9 88
77 5\le 5 100\le 100 =5n2=5n^2 1414
88 25\le 25 103\le 10^3 =10n=10n 1515
99 105\le 10^5 5×104\le 5 \times 10^4 =max(0,2n3)=\max(0, 2n - 3) 3030

!!!! means double factorial

Translated by ChatGPT 5