CF1521C.Nastia and a Hidden Permutation
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is an interactive problem!
Nastia has a hidden permutation p of length n consisting of integers from 1 to n. You, for some reason, want to figure out the permutation. To do that, you can give her an integer t (1≤t≤2), two different indices i and j (1≤i,j≤n, i=j), and an integer x (1≤x≤n−1).
Depending on t, she will answer:
- t=1: max(min(x,pi),min(x+1,pj));
- t=2: min(max(x,pi),max(x+1,pj)).
You can ask Nastia at most ⌊23⋅n⌋+30 times. It is guaranteed that she will not change her permutation depending on your queries. Can you guess the permutation?
这是一个交互式问题!
娜斯佳有一个长度为 n 的隐藏排列 p,其中包含从 1 到 n 的整数。出于某种原因,你想推断出该排列。为此,你可以向她提供一个整数 t(1≤t≤2)、两个不同的下标 i 和 j(1≤i,j≤n,且 i=j),以及一个整数 x(1≤x≤n−1)。
根据 t 的取值,她将给出如下回答:
- 若 t=1:max(min(x,pi),min(x+1,pj));
- 若 t=2:min(max(x,pi),max(x+1,pj))。
你最多可向娜斯佳提问 ⌊23⋅n⌋+30 次。保证她在整个过程中不会根据你的提问而更改其排列。你能猜出这个排列吗?
输入格式
The input consists of several test cases. In the beginning, you receive the integer T (1≤T≤10000) — the number of test cases.
At the beginning of each test case, you receive an integer n (3≤n≤104) — the length of the permutation p.
It's guaranteed that the permutation is fixed beforehand and that the sum of n in one test doesn't exceed 2⋅104.
输入包含多个测试用例。首先,你将接收到一个整数 T(1≤T≤10000),表示测试用例的数量。
对于每个测试用例,首先你将接收到一个整数 n(3≤n≤104),表示排列 p 的长度。
保证该排列在测试开始前已固定,且单个测试中所有 n 的总和不超过 2⋅104。
输入输出样例
输入#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].
We print: "? 2 4 1 3" and get back min(max(3,p4),max(4,p1))=3.
We print: "? 1 2 4 2" and get back max(min(2,p2),min(3,p4))=2.
Consider the second test case.
The hidden permutation is [2,5,3,4,1].
We print: "? 2 3 4 2" and get back min(max(2,p3),max(3,p4))=3.
考虑第一个测试用例。
隐藏的排列为 [3,1,4,2]。
我们输出:"? 2 4 1 3",并得到返回值 min(max(3,p4),max(4,p1))=3。
我们输出:"? 1 2 4 2",并得到返回值 max(min(2,p2),min(3,p4))=2。
考虑第二个测试用例。
隐藏的排列为 [2,5,3,4,1]。
我们输出:"? 2 3 4 2",并得到返回值 min(max(2,p3),max(3,p4))=3。
输入解题思路,AI测评打分。不知道怎么写?