CF1621C.Hidden Permutations
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
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.
这是一个交互式问题。
评测组持有一个长度为 n 的排列 p,并希望你猜出它。为此,评测组构造了另一个长度为 n 的排列 q。初始时,q 是一个恒等排列(即对所有 i,均有 qi=i)。
你可以进行查询,以获取任意位置 i 处的 qi 值。每次查询后,评测组将按如下方式更新 q:
- 首先,评测组构造一个新的长度为 n 的排列 q′,使得对所有 i,均有 qi′=qpi;
- 然后,评测组将排列 q 替换为排列 q′。
你至多可以进行 2n 次查询来猜出 p。
输入格式
The first line of input contains a single integer t (1≤t≤1000) — the number of test cases.
输入的第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。
输入输出样例
输入#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.
在第一个测试用例中,隐藏的排列为 p=[4,2,1,3]。
第一次查询前,q=[1,2,3,4],因此该查询的答案为 q3=3。
第二次查询前,q=[4,2,1,3],因此该查询的答案为 q2=2。
第三次查询前,q=[3,2,4,1],因此该查询的答案为 q4=1。
在第二个测试用例中,隐藏的排列为 p=[1,3,4,2]。
空行仅用于提高可读性。评测系统中不会出现空行。
输入解题思路,AI测评打分。不知道怎么写?