CF1656G.Cycle Palindrome
NOI/NOI+/CTSC
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
We say that a sequence of n integers a1,a2,…,an is a palindrome if for all 1≤i≤n, ai=an−i+1. You are given a sequence of n integers a1,a2,…,an and you have to find, if it exists, a cycle permutation σ so that the sequence aσ(1),aσ(2),…,aσ(n) is a palindrome.
A permutation of 1,2,…,n is a bijective function from 1,2,…,n to 1,2,…,n. We say that a permutation σ is a cycle permutation if 1,σ(1),σ2(1),…,σn−1(1) are pairwise different numbers. Here σm(1) denotes m timesσ(σ(…σ(1)…)).
我们称一个由 n 个整数组成的序列 a1,a2,…,an 是回文序列,当且仅当对所有 1≤i≤n,均有 ai=an−i+1。现给定一个由 n 个整数组成的序列 a1,a2,…,an,你需要判断是否存在一个循环置换 σ,使得重排后的序列 aσ(1),aσ(2),…,aσ(n) 构成回文序列。
集合 {1,2,…,n} 的一个置换是指从 {1,2,…,n} 到 {1,2,…,n} 的一个双射函数。我们称一个置换 σ 是循环置换,当且仅当 1,σ(1),σ2(1),…,σn−1(1) 两两互不相同。此处 σm(1) 表示将 σ 连续作用 m 次于 1 所得的结果,即 m 次σ(σ(…σ(1)…))。
输入格式
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤3⋅104) — the number of test cases. Description of the test cases follows.
The first line of each test case contains an integer n (2≤n≤2⋅105) — the size of the sequence.
The second line of each test case contains n integers a1,…,an (1≤ai≤n).
The sum of n for all test cases is at most 2⋅105.
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤3⋅104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(2≤n≤2⋅105),表示序列的长度。
每个测试用例的第二行包含 n 个整数 a1,…,an(1≤ai≤n)。
所有测试用例的 n 值之和不超过 2⋅105。
输出格式
For each test case, output one line with YES if a cycle permutation exists, otherwise output one line with NO.
If the answer is YES, output one additional line with n integers σ(1),σ(2),…,σ(n), the permutation. If there is more than one permutation, you may print any.
对于每个测试用例,如果存在一个循环排列,则输出一行 YES;否则输出一行 NO。
如果答案为 YES,则再输出一行包含 n 个整数 σ(1),σ(2),…,σ(n) 的排列。若存在多个满足条件的排列,输出任意一个即可。
输入输出样例
输入#1
3 4 1 2 2 1 3 1 2 1 7 1 3 3 3 1 2 2
输出#1
YES 3 1 4 2 NO YES 5 3 7 2 6 4 1
输入解题思路,AI测评打分。不知道怎么写?