Codeforces Round 1075 (Div. 2)
C1
XOR Convenience (Easy Version)
Codeforces
1300
原题
← BC2 →
翻译中…

This is the easy version of the problem. The difference between the versions is that in this version, $2 \le i \le n-1$. Note that a correct solution for the hard version is not necessarily a correct solution for the easy version.

翻译中…

Given a natural number $n$. Find a permutation$^{\text{∗}}$ $p$ of length $n$, such that for each $i$ ($\style{color:red}{2 \le i \le n-1}$) there exists a $j$ ($\style{color:red}{i \le j \le n}$) such that $p_i = p_j \oplus i$ $^{\text{†}}$.

翻译中…

It can be proven that under the constraints of the problem, there exists at least one suitable permutation $p$.

翻译中…

$^{\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). $^{\text{†}}$$\oplus$ denotes the bitwise XOR operation.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The only line of each test case contains a single integer $n$ ($3 \leq n \leq 2 \cdot 10^5$) — the length of the permutation.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, output $n$ integers $p_1,p_2,\ldots,p_n$ — the permutation $p$.

翻译中…

If there are multiple solutions, you may output any of them.

翻译中…

Note

翻译中…

In the first test case, the permutation $p = [2,1,3]$ is suitable since $p_2 = 1$ and $p_3 \oplus 2 = 1$.

翻译中…

In the second test case, the permutation $p = [3,6,2,5,1,4]$ is suitable, as:

翻译中…
  • $p_2 = 6 = 4 \oplus 2 = p_6 \oplus 2$
  • $p_3 = 2 = 1 \oplus 3 = p_5 \oplus 3$
  • $p_4 = 5 = 1 \oplus 4 = p_5 \oplus 4$
  • $p_5 = 1 = 4 \oplus 5 = p_6 \oplus 5$
翻译中…

样例

Input #1
2
3
6
Output #1
2 1 3
3 6 2 5 1 4
InputCopy OutputCopy
题目信息
题号
2189C1
时间限制
2 s
内存限制
256 MB
标签
位运算
构造
数学

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