CF1405A.Permutation Forgery

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array) and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

Let pp be any permutation of length nn. We define the fingerprint F(p)F(p) of pp as the sorted array of sums of adjacent elements in pp. More formally,

F(p)=\\mathrm{sort}(\[p\_1+p\_2,p\_2+p\_3,\\ldots,p\_{n-1}+p\_n\]).

For example, if n=4n=4 and p=[1,4,2,3],p=[1,4,2,3], then the fingerprint is given by F(p)=sort([1+4,4+2,2+3])=sort([5,6,5])=[5,5,6]F(p)=\mathrm{sort}([1+4,4+2,2+3])=\mathrm{sort}([5,6,5])=[5,5,6].

You are given a permutation pp of length nn. Your task is to find a different permutation p′p' with the same fingerprint. Two permutations pp and p′p' are considered different if there is some index ii such that pi≠pi′p_i \ne p'_i.

长度为 nn 的排列是指由 11 到 nn 中互不相同的 nn 个整数以任意顺序组成的数组。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列,但 [1,2,2][1,2,2] 不是排列(数组中数字 22 出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n=3,但数组中出现了 44)。

设 pp 是任意一个长度为 nn 的排列。我们定义 pp 的指纹 F(p)F(p) 为 pp 中所有相邻元素之和所构成的数组经升序排序后的结果。更准确地说,

F(p)=sort([p1+p2,p2+p3,…,pn−1+pn]).F(p)=\mathrm{sort}([p_1+p_2,p_2+p_3,\ldots,p_{n-1}+p_n]).

例如,若 n=4n=4 且 p=[1,4,2,3]p=[1,4,2,3],则其指纹为
F(p)=sort([1+4,4+2,2+3])=sort([5,6,5])=[5,5,6]F(p)=\mathrm{sort}([1+4,4+2,2+3])=\mathrm{sort}([5,6,5])=[5,5,6]。

现给出一个长度为 nn 的排列 pp。你的任务是找出另一个与 pp 具有相同指纹的排列 p′p'。若存在某个下标 ii 使得 pi≠pi′p_i \ne p'_i,则称排列 pp 与 p′p' 不同。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤6681 \le t \le 668). Description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤1002\le n\le 100) — the length of the permutation.

The second line of each test case contains nn integers p1,…,pnp_1,\ldots,p_n (1≤pi≤n1\le p_i\le n). It is guaranteed that pp is a permutation.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤6681 \le t \le 668)。随后是测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1002\le n\le 100)—— 表示排列的长度。

每个测试用例的第二行包含 nn 个整数 p1,…,pnp_1,\ldots,p_n(1≤pi≤n1\le p_i\le n)。保证 pp 是一个排列。

输出格式

For each test case, output nn integers p1′,…,pn′p'_1,\ldots, p'_n — a permutation such that p′≠pp'\ne p and F(p′)=F(p)F(p')=F(p).

We can prove that for every permutation satisfying the input constraints, a solution exists.

If there are multiple solutions, you may output any.

对于每个测试用例,输出 nn 个整数 p1′,…,pn′p'_1,\ldots, p'_n —— 一个满足 p′≠pp'\ne p 且 F(p′)=F(p)F(p')=F(p) 的排列。

我们可以证明:对每个满足输入约束的排列,解均存在。

若存在多个解,你可以输出其中任意一个。

输入输出样例

  • 输入#1

    3
    2
    1 2
    6
    2 1 6 5 4 3
    5
    2 4 3 1 5

    输出#1

    2 1
    1 2 5 6 3 4
    3 1 5 2 4

说明/提示

In the first test case, F(p)=sort([1+2])=[3]F(p)=\mathrm{sort}([1+2])=[3].

And F(p′)=sort([2+1])=[3]F(p')=\mathrm{sort}([2+1])=[3].

In the second test case, F(p)=sort([2+1,1+6,6+5,5+4,4+3])=sort([3,7,11,9,7])=[3,7,7,9,11]F(p)=\mathrm{sort}([2+1,1+6,6+5,5+4,4+3])=\mathrm{sort}([3,7,11,9,7])=[3,7,7,9,11].

And F(p′)=sort([1+2,2+5,5+6,6+3,3+4])=sort([3,7,11,9,7])=[3,7,7,9,11]F(p')=\mathrm{sort}([1+2,2+5,5+6,6+3,3+4])=\mathrm{sort}([3,7,11,9,7])=[3,7,7,9,11].

In the third test case, F(p)=sort([2+4,4+3,3+1,1+5])=sort([6,7,4,6])=[4,6,6,7]F(p)=\mathrm{sort}([2+4,4+3,3+1,1+5])=\mathrm{sort}([6,7,4,6])=[4,6,6,7].

And F(p′)=sort([3+1,1+5,5+2,2+4])=sort([4,6,7,6])=[4,6,6,7]F(p')=\mathrm{sort}([3+1,1+5,5+2,2+4])=\mathrm{sort}([4,6,7,6])=[4,6,6,7].

在第一个测试用例中,F(p)=sort([1+2])=[3]F(p)=\mathrm{sort}([1+2])=[3]。

而 F(p′)=sort([2+1])=[3]F(p')=\mathrm{sort}([2+1])=[3]。

在第二个测试用例中,F(p)=sort([2+1,1+6,6+5,5+4,4+3])=sort([3,7,11,9,7])=[3,7,7,9,11]F(p)=\mathrm{sort}([2+1,1+6,6+5,5+4,4+3])=\mathrm{sort}([3,7,11,9,7])=[3,7,7,9,11]。

而 F(p′)=sort([1+2,2+5,5+6,6+3,3+4])=sort([3,7,11,9,7])=[3,7,7,9,11]F(p')=\mathrm{sort}([1+2,2+5,5+6,6+3,3+4])=\mathrm{sort}([3,7,11,9,7])=[3,7,7,9,11]。

在第三个测试用例中,F(p)=sort([2+4,4+3,3+1,1+5])=sort([6,7,4,6])=[4,6,6,7]F(p)=\mathrm{sort}([2+4,4+3,3+1,1+5])=\mathrm{sort}([6,7,4,6])=[4,6,6,7]。

而 F(p′)=sort([3+1,1+5,5+2,2+4])=sort([4,6,7,6])=[4,6,6,7]F(p')=\mathrm{sort}([3+1,1+5,5+2,2+4])=\mathrm{sort}([4,6,7,6])=[4,6,6,7]。

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

首页