CF1621C.Hidden Permutations
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is an interactive problem.
The jury has a permutation p of length n and wants you to guess it. For this, the jury created another permutation q of length n . Initially, q is an identity permutation ( qi=i for all i ).
You can ask queries to get qi for any i you want. After each query, the jury will change q in the following way:
- At first, the jury will create a new permutation q′ of length n such that qi′=qpi for all i .
- Then the jury will replace permutation q with pemutation q′ .
You can make no more than 2n queries in order to quess p .
输入格式
The first line of input contains a single integer t ( 1≤t≤1000 ) — the number of test cases.
输出格式
Interaction in each test case starts after reading the single integer n ( 1≤n≤104 ) — the length of permutations p and q .
To get the value of qi , output the query in the format ? i ( 1≤i≤n ). After that you will receive the value of qi .
You can make at most 2n queries. After the incorrect query you will receive 0 and you should exit immediately to get Wrong answer verdict.
When you will be ready to determine p , output p in format ! p1 p2 … pn . After this you should go to the next test case or exit if it was the last test case. Printing the permutation is not counted as one of 2n queries.
After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. 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 documentation for other languages.
It is guaranteed that the sum of n over all test cases doesn't exceed 104 . The interactor is not adaptive in this problem.
Hacks:
To hack, use the following format:
The first line contains the single integer t — the number of test cases.
The first line of each test case contains the single integer n — the length of the permutations p and q . The second line of each test case contains n integers p1,p2,…,pn — the hidden permutation for this test case.
输入输出样例
输入#1
2 4 3 2 1 4 2 4 4
输出#1
? 3 ? 2 ? 4 ! 4 2 1 3 ? 2 ? 3 ? 2 ! 1 3 4 2
说明/提示
In the first test case the hidden permutation p=[4,2,1,3] .
Before the first query q=[1,2,3,4] so answer for the query will be q3=3 .
Before the second query q=[4,2,1,3] so answer for the query will be q2=2 .
Before the third query q=[3,2,4,1] so answer for the query will be q4=1 .
In the second test case the hidden permutation p=[1,3,4,2] .
Empty strings are given only for better readability. There will be no empty lines in the testing system.