#P14025. [ICPC 2024 Nanjing R] P ⊕ Q = R

    ID: 13997 远端评测题 4000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2024Special Judge构造ICPC分类讨论南京

[ICPC 2024 Nanjing R] P ⊕ Q = R

Description

Alice wants to train herself to solve constructive problems. So her friend Kei, a super artificial intelligence, generates the following problem for Alice.

Given an integer nn, construct two permutations P=p1,p2,,pnP = p_1,p_2,\cdots,p_n and Q=q1,q2,,qnQ = q_1,q_2,\cdots,q_n of 0,1,,(n1)0,1,\dots,(n-1), such that the sequence R=r1,r2,,rnR = r_1,r_2,\cdots,r_n is still a permutation of 0,1,,(n1)0,1,\dots,(n-1), where ri=piqir_i = p_i \oplus q_i. Here xyx \oplus y means the bitwise exclusive-or of xx and yy.

Alice solves this problem with her powerful calculating ability and she decides to share this problem with you. Can you solve it?

Input Format

There are multiple test cases. The first line of the input contains an integer TT indicating the number of test cases. For each test case:

The first and only line contains one integer nn (1n2×1051 \leq n \leq 2 \times 10^5) indicating the length of the permutation.

It is guaranteed that the sum of nn of all test cases will not exceed 2×1062 \times 10^6.

Output Format

For each test case:

If there exist two permutations satisfying the constraint, first output Yes\texttt{Yes} in one line. Then output a second line containing nn integers p1,p2,,pnp_1,p_2,\dots,p_n separated by a space. Finally output a third line containing nn integers q1,q2,,qnq_1,q_2,\dots,q_n separated by a space. If there are multiple valid answers, you can output any of them.

If there do not exist two permutations satisfying the constraint, just output No\texttt{No} in one line.

2
3
4
No
Yes
0 2 1 3
3 2 0 1

Hint

For the second test case, R={3,0,1,2}R = \{ 3,0,1,2\} is still a permutation of 0,1,2,30,1,2,3.

:::align{center} :::