CF1584D.Guess the Permutation

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

This is an interactive problem.

Jury initially had a sequence aa of length nn , such that ai=ia_i = i .

The jury chose three integers ii , jj , kk , such that 1i<j<kn1 \leq i < j < k \leq n , ji>1j - i > 1 . After that, Jury reversed subsegments [i,j1][i, j - 1] and [j,k][j, k] of the sequence aa .

Reversing a subsegment [l,r][l, r] of the sequence aa means reversing the order of elements al,al+1,,ara_l, a_{l+1}, \ldots, a_r in the sequence, i. e. ala_l is swapped with ara_r , al+1a_{l+1} is swapped with ar1a_{r-1} , etc.

You are given the number nn and you should find ii , jj , kk after asking some questions.

In one question you can choose two integers ll and rr ( 1lrn1 \leq l \leq r \leq n ) and ask the number of inversions on the subsegment [l,r][l, r] of the sequence aa . You will be given the number of pairs (i,j)(i, j) such that li<jrl \leq i < j \leq r , and ai>aja_i > a_j .

Find the chosen numbers ii , jj , kk after at most 4040 questions.

The numbers ii , jj , and kk are fixed before the start of your program and do not depend on your queries.

输入格式

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

The single line of each test case contains a single integer nn ( 4n1094 \leq n \leq 10^9 ). After reading it you should start an interaction process by asking questions for that test case. After giving an answer you should:

  • Terminate your program if that is the last test case.
  • Proceed to the next test case otherwise.

输出格式

To ask number of inversions on a subsegment [l,r][l, r] , print "? l r", where ( 1lrn1 \leq l \leq r \leq n ). You can ask at most 4040 questions in each test case. As a result you should read a single integer xx .

  • If x=1x = -1 , your program made an invalid question or you exceeded the number of questions for that test case. Your program should terminate immediately (otherwise it can get any verdict instead of "Wrong Answer").
  • Otherwise xx is equal to the number of inversions on the subsegment [l,r][l, r] of the sequence aa .

To give the answer, print "! i j k", where ii , jj , kk are the numbers you found. You should continue solving the next test cases or terminate the program after that.

After printing a question or an answer do not forget to print the end of line and flush the output. Otherwise, you will get an "Idleness limit exceeded" verdict. 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 the documentation for other languages.

Hacks

To make a hack, use the following format:

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

Each of the next tt lines contains four integers nn , ii , jj , kk ( 4n1094 \leq n \leq 10^9 , 1i<j<kn1 \leq i < j < k \leq n , ji>1j - i > 1 ).

输入输出样例

  • 输入#1

    2 
    5 
    
    4 
    
    3 
    
    3 
    
    5 
    
    2 
    
    2 
    
    1

    输出#1

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

说明/提示

In the first test case, i=1i = 1 , j=3j = 3 , k=5k = 5 , so the sequence aa is [2,1,5,4,3][2, 1, 5, 4, 3] .

In the second test case, i=2i = 2 , j=4j = 4 , k=5k = 5 , so the sequence aa is [1,3,2,5,4][1, 3, 2, 5, 4] .

首页