CF1584D.Guess the Permutation

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

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 1≤i<j<k≤n1 \leq i \lt j \lt k \leq n, j−i>1j - i \gt 1. After that, Jury reversed subsegments [i,j−1][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 ar−1a_{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 (1≤l≤r≤n1 \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 l≤i<j≤rl \leq i \lt j \leq r, and ai>aja_i \gt 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.

这是一个交互式问题。

评测组最初有一个长度为 nn 的序列 aa,满足 ai=ia_i = i。

评测组选择了三个整数 ii、jj、kk,满足 1≤i<j<k≤n1 \leq i \lt j \lt k \leq n 且 j−i>1j - i \gt 1。随后,评测组对序列 aa 的两个子段 [i,j−1][i, j - 1] 和 [j,k][j, k] 分别执行了翻转操作。

对序列 aa 的子段 [l,r][l, r] 进行翻转,是指将元素 al,al+1,…,ara_l, a_{l+1}, \ldots, a_r 的顺序反转,即 ala_l 与 ara_r 交换,al+1a_{l+1} 与 ar−1a_{r-1} 交换,依此类推。

你将获得整数 nn,需通过提出若干询问来确定 ii、jj、kk 的值。

每次询问中,你可以选择两个整数 ll 和 rr(满足 1≤l≤r≤n1 \leq l \leq r \leq n),并查询序列 aa 在子段 [l,r][l, r] 上的逆序对数量。你将得到满足 l≤i<j≤rl \leq i \lt j \leq r 且 ai>aja_i \gt a_j 的数对 (i,j)(i, j) 的个数。

你需要在至多 4040 次询问内找出所选的 ii、jj、kk。

数字 ii、jj、kk 在你的程序开始运行前即已固定,且不依赖于你提出的任何询问。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1001 \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 (4≤n≤1094 \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.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅占一行,包含一个整数 nn(4≤n≤1094 \leq n \leq 10^9)。读入该数后,你需要针对该测试用例启动交互过程并提出问题。在给出答案后,你应当:

  • 若这是最后一个测试用例,则终止你的程序;
  • 否则,继续处理下一个测试用例。

输入输出样例

  • 输入#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].

在第一个测试用例中,i=1i = 1,j=3j = 3,k=5k = 5,因此序列 aa 为 [2,1,5,4,3][2, 1, 5, 4, 3]。

在第二个测试用例中,i=2i = 2,j=4j = 4,k=5k = 5,因此序列 aa 为 [1,3,2,5,4][1, 3, 2, 5, 4]。

输入解题思路,AI测评打分。不知道怎么写?

首页