Codeforces Round 965 (Div. 2)
B
Minimize Equal Sum Subarrays
Codeforces
1000
原题
← AC →
翻译中…

It is known that Farmer John likes Permutations, but I like them too!— Sun Tzu, The Art of Constructing Permutations

翻译中…

You are given a permutation$^{\text{∗}}$ $p$ of length $n$.

翻译中…

Find a permutation $q$ of length $n$ that minimizes the number of pairs ($i, j$) ($1 \leq i \leq j \leq n$) such that $p_i + p_{i+1} + \ldots + p_j = q_i + q_{i+1} + \ldots + q_j$.

翻译中…

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).

翻译中…

Input

翻译中…

The first line contains $t$ ($1 \leq t \leq 10^4$) — the number of test cases.

翻译中…

The first line of each test case contains $n$ ($1 \leq n \leq 2 \cdot 10^5$).

翻译中…

The following line contains $n$ space-separated integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq n$) — denoting the permutation $p$ of length $n$.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output one line containing any permutation of length $n$ (the permutation $q$) such that $q$ minimizes the number of pairs.

翻译中…

Note

翻译中…

For the first test, there exists only one pair ($i, j$) ($1 \leq i \leq j \leq n$) such that $p_i + p_{i+1} + \ldots + p_j = q_i + q_{i+1} + \ldots + q_j$, which is ($1, 2$). It can be proven that no such $q$ exists for which there are no pairs.

翻译中…

样例

Input #1
3
2
1 2
5
1 2 3 4 5
7
4 7 5 1 2 6 3
Output #1
2 1
3 5 4 2 1
6 2 1 4 7 3 5
InputCopy OutputCopy
题目信息
题号
1998B
时间限制
1.5 s
内存限制
256 MB
标签
构造
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。