#P9635. 「yyOI R1」youyou 的异或

    ID: 9876 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>Special JudgeO2优化位运算构造Ad-hoc

「yyOI R1」youyou 的异或

Background

youyou is very weak, but he really likes constructing strange sequences.

Problem Description

This problem uses Special Judge.

youyou likes sequences very much, so he wants you to construct a positive integer sequence {ai}\{a_i\} of length nn.

youyou likes XOR, so he requires the constructed sequence to satisfy $a_1 \oplus a_2 \oplus a_3 \oplus \cdots \oplus a_{n-1} \oplus a_n = n$ (where \oplus denotes XOR).

youyou really hates identical numbers, so he requires that all numbers in the sequence are pairwise distinct.

But youyou does not want the numbers in this sequence to be too large, so he requires that the sum of all numbers in the sequence does not exceed n2n^2, i.e., i=1nain2\displaystyle\sum_{i=1}^n a_i \le n^2.

Now you need to construct a sequence that satisfies all of youyou's requirements. If there is no solution, output -1. If there are multiple answers, output any one of them.

You need to answer TT test cases.

Input Format

The first line contains a positive integer TT.

The next TT lines each contain an integer nn, meaning you need to construct a required sequence of length nn.

Output Format

Output TT lines in total.

If the ii-th line corresponds to constructing a sequence of length nn, then output exactly nn numbers on that line, representing your constructed sequence. Note that every number in the sequence must be a positive integer. If such a sequence cannot be constructed, output -1 on this line.

3
1
2
5
1
3 1
1 4 5 3 6

Hint

Sample Explanation

For n=1n = 1, one feasible solution is {1}\{1\}.

For n=2n = 2, one feasible solution is {3,1}\{3,1\}.

For n=5n = 5, one feasible solution is {1,4,5,3,6}\{1,4,5,3,6\}, because 14536=51 ⊕ 4 ⊕ 5 ⊕ 3 ⊕ 6 = 5, and 1+4+5+3+6=19521+4+5+3+6 =19\le 5^2, and all numbers in the sequence are also pairwise distinct.

Constraints

For 5%5\% of the testdata, n5n \le 5.

For 15%15\% of the testdata, n10n \le 10.

For 40%40\% of the testdata, n1000n \le 1000.

For 70%70\% of the testdata, n105n \le 10^5.

For 100%100\% of the testdata, 1n5×1051 \le n \le 5 × 10^5, and 1T101 \le T \le 10.

Translated by ChatGPT 5