CF1656G.Cycle Palindrome

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

We say that a sequence of nn integers a1,a2,,ana_1, a_2, \ldots, a_n is a palindrome if for all 1in1 \leq i \leq n , ai=ani+1a_i = a_{n-i+1} . You are given a sequence of nn integers a1,a2,,ana_1, a_2, \ldots, a_n and you have to find, if it exists, a cycle permutation σ\sigma so that the sequence aσ(1),aσ(2),,aσ(n)a_{\sigma(1)}, a_{\sigma(2)}, \ldots, a_{\sigma(n)} is a palindrome.

A permutation of 1,2,,n1, 2, \ldots, n is a bijective function from {1,2,,n}\{1, 2, \ldots, n\} to {1,2,,n}\{1, 2, \ldots, n\} . We say that a permutation σ\sigma is a cycle permutation if 1,σ(1),σ2(1),,σn1(1)1, \sigma(1), \sigma^2(1), \ldots, \sigma^{n-1}(1) are pairwise different numbers. Here σm(1)\sigma^m(1) denotes σ(σ(σm times(1)))\underbrace{\sigma(\sigma(\ldots \sigma}_{m \text{ times}}(1) \ldots)) .

输入格式

The input consists of multiple test cases. The first line contains a single integer tt ( 1t31041 \leq t \leq 3 \cdot 10^4 ) — the number of test cases. Description of the test cases follows.

The first line of each test case contains an integer nn ( 2n21052 \leq n \leq 2 \cdot 10^5 ) — the size of the sequence.

The second line of each test case contains nn integers a1,,ana_1, \ldots, a_n ( 1ain1 \leq a_i \leq n ).

The sum of nn for all test cases is at most 21052 \cdot 10^5 .

输出格式

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 nn integers σ(1),σ(2),,σ(n)\sigma(1), \sigma(2), \ldots, \sigma(n) , the permutation. If there is more than one permutation, you may print any.

输入输出样例

  • 输入#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
首页