CF1521C.Nastia and a Hidden Permutation

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is an interactive problem!

Nastia has a hidden permutation pp of length nn consisting of integers from 11 to nn. You, for some reason, want to figure out the permutation. To do that, you can give her an integer tt (1≤t≤21 \le t \le 2), two different indices ii and jj (1≤i,j≤n1 \le i, j \le n, i≠ji \neq j), and an integer xx (1≤x≤n−11 \le x \le n - 1).

Depending on tt, she will answer:

  • t=1t = 1: max⁡(min⁡(x,pi),min⁡(x+1,pj))\max{(\min{(x, p_i)}, \min{(x + 1, p_j)})};
  • t=2t = 2: min⁡(max⁡(x,pi),max⁡(x+1,pj))\min{(\max{(x, p_i)}, \max{(x + 1, p_j)})}.

You can ask Nastia at most ⌊3⋅n2⌋+30\lfloor \frac {3 \cdot n} { 2} \rfloor + 30 times. It is guaranteed that she will not change her permutation depending on your queries. Can you guess the permutation?

这是一个交互式问题!

娜斯佳有一个长度为 nn 的隐藏排列 pp,其中包含从 11 到 nn 的整数。出于某种原因,你想推断出该排列。为此,你可以向她提供一个整数 tt(1≤t≤21 \le t \le 2)、两个不同的下标 ii 和 jj(1≤i,j≤n1 \le i, j \le n,且 i≠ji \neq j),以及一个整数 xx(1≤x≤n−11 \le x \le n - 1)。

根据 tt 的取值,她将给出如下回答:

  • 若 t=1t = 1:max⁡(min⁡(x,pi),min⁡(x+1,pj))\max{(\min{(x, p_i)}, \min{(x + 1, p_j)})};
  • 若 t=2t = 2:min⁡(max⁡(x,pi),max⁡(x+1,pj))\min{(\max{(x, p_i)}, \max{(x + 1, p_j)})}。

你最多可向娜斯佳提问 ⌊3⋅n2⌋+30\lfloor \frac {3 \cdot n} { 2} \rfloor + 30 次。保证她在整个过程中不会根据你的提问而更改其排列。你能猜出这个排列吗?

输入格式

The input consists of several test cases. In the beginning, you receive the integer TT (1≤T≤10 0001 \le T \le 10\,000) — the number of test cases.

At the beginning of each test case, you receive an integer nn (3≤n≤1043 \le n \le 10^4) — the length of the permutation pp.

It's guaranteed that the permutation is fixed beforehand and that the sum of nn in one test doesn't exceed 2⋅1042 \cdot 10^4.

输入包含多个测试用例。首先,你将接收到一个整数 TT(1≤T≤10 0001 \le T \le 10\,000),表示测试用例的数量。

对于每个测试用例,首先你将接收到一个整数 nn(3≤n≤1043 \le n \le 10^4),表示排列 pp 的长度。

保证该排列在测试开始前已固定,且单个测试中所有 nn 的总和不超过 2⋅1042 \cdot 10^4。

输入输出样例

  • 输入#1

    2
    4
    
    3
    
    2
    
    5
    
    3

    输出#1

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

说明/提示

Consider the first test case.

The hidden permutation is [3,1,4,2][3, 1, 4, 2].

We print: "? 22 44 11 33" and get back min⁡(max⁡(3,p4),max⁡(4,p1))=3\min{(\max{(3, p_4}), \max{(4, p_1)})} = 3.

We print: "? 11 22 44 22" and get back max⁡(min⁡(2,p2),min⁡(3,p4))=2\max{(\min{(2, p_2)}, \min{(3, p_4)})} = 2.

Consider the second test case.

The hidden permutation is [2,5,3,4,1][2, 5, 3, 4, 1].

We print: "? 22 33 44 22" and get back min⁡(max⁡(2,p3),max⁡(3,p4))=3\min{(\max{(2, p_3}), \max{(3, p_4)})} = 3.

考虑第一个测试用例。

隐藏的排列为 [3,1,4,2][3, 1, 4, 2]。

我们输出:"? 22 44 11 33",并得到返回值 min⁡(max⁡(3,p4),max⁡(4,p1))=3\min{(\max{(3, p_4}), \max{(4, p_1)})} = 3。

我们输出:"? 11 22 44 22",并得到返回值 max⁡(min⁡(2,p2),min⁡(3,p4))=2\max{(\min{(2, p_2)}, \min{(3, p_4)})} = 2。

考虑第二个测试用例。

隐藏的排列为 [2,5,3,4,1][2, 5, 3, 4, 1]。

我们输出:"? 22 33 44 22",并得到返回值 min⁡(max⁡(2,p3),max⁡(3,p4))=3\min{(\max{(2, p_3}), \max{(3, p_4)})} = 3。

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

首页