CF1621C.Hidden Permutations

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is an interactive problem.

The jury has a permutation pp of length nn and wants you to guess it. For this, the jury created another permutation qq of length nn. Initially, qq is an identity permutation (qi=iq_i = i for all ii).

You can ask queries to get qiq_i for any ii you want. After each query, the jury will change qq in the following way:

  • At first, the jury will create a new permutation q′q' of length nn such that qi′=qpiq'_i = q_{p_i} for all ii.
  • Then the jury will replace permutation qq with pemutation q′q'.

You can make no more than 2n2n queries in order to quess pp.

这是一个交互式问题。

评测组持有一个长度为 nn 的排列 pp,并希望你猜出它。为此,评测组构造了另一个长度为 nn 的排列 qq。初始时,qq 是一个恒等排列(即对所有 ii,均有 qi=iq_i = i)。

你可以进行查询,以获取任意位置 ii 处的 qiq_i 值。每次查询后,评测组将按如下方式更新 qq:

  • 首先,评测组构造一个新的长度为 nn 的排列 q′q',使得对所有 ii,均有 qi′=qpiq'_i = q_{p_i};
  • 然后,评测组将排列 qq 替换为排列 q′q'。

你至多可以进行 2n2n 次查询来猜出 pp。

输入格式

The first line of input contains a single integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases.

输入的第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 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]p = [4, 2, 1, 3].

Before the first query q=[1,2,3,4]q = [1, 2, 3, 4] so answer for the query will be q3=3q_3 = 3.

Before the second query q=[4,2,1,3]q = [4, 2, 1, 3] so answer for the query will be q2=2q_2 = 2.

Before the third query q=[3,2,4,1]q = [3, 2, 4, 1] so answer for the query will be q4=1q_4 = 1.

In the second test case the hidden permutation p=[1,3,4,2]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]p = [4, 2, 1, 3]。

第一次查询前,q=[1,2,3,4]q = [1, 2, 3, 4],因此该查询的答案为 q3=3q_3 = 3。

第二次查询前,q=[4,2,1,3]q = [4, 2, 1, 3],因此该查询的答案为 q2=2q_2 = 2。

第三次查询前,q=[3,2,4,1]q = [3, 2, 4, 1],因此该查询的答案为 q4=1q_4 = 1。

在第二个测试用例中,隐藏的排列为 p=[1,3,4,2]p = [1, 3, 4, 2]。

空行仅用于提高可读性。评测系统中不会出现空行。

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

首页