CF2189C1.XOR Convenience (Easy Version)

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The difference between the versions is that in this version, 2≤i≤n−12 \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 nn. Find a permutation∗^{\text{∗}} pp of length nn, such that for each ii (\style{color:red}{2 \le i \le n-1}) there exists a jj (\style{color:red}{i \le j \le n}) such that pi=pj⊕ip_i = p_j \oplus i †^{\text{†}}.

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

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

†^{\text{†}}⊕\oplus denotes the bitwise XOR operation.

这是该问题的简单版本。两个版本的区别在于,在此版本中,2≤i≤n−12 \le i \le n-1。请注意,困难版本的正确解法不一定适用于简单版本。

给定一个正整数 nn。请构造一个长度为 nn 的排列∗^{\text{∗}} pp,使得对每个 ii(\style{color:red}{2 \le i \le n-1}),均存在某个 jj(\style{color:red}{i \le j \le n}),满足 pi=pj⊕ip_i = p_j \oplus i †^{\text{†}}。

在本题约束下,可以证明至少存在一个满足条件的排列 pp。

∗^{\text{∗}} 长度为 nn 的排列是指由 11 到 nn 中互不相同的 nn 个整数以任意顺序组成的数组。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列,而 [1,2,2][1,2,2] 不是排列(数字 22 在数组中出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n=3,但数组中包含了 44)。

†^{\text{†}} ⊕\oplus 表示按位异或运算。

输入格式

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

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

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例仅一行,包含一个整数 nn(3≤n≤2⋅1053 \leq n \leq 2 \cdot 10^5)—— 表示排列的长度。

保证所有测试用例中 nn 的总和不超过 2⋅1052\cdot 10^5。

输出格式

For each test case, output nn integers p1,p2,…,pnp_1,p_2,\ldots,p_n — the permutation pp.

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

对于每个测试用例,输出 nn 个整数 p1,p2,…,pnp_1,p_2,\ldots,p_n —— 即排列 pp。

如果存在多个解,你可以输出其中任意一个。

输入输出样例

  • 输入#1

    2
    3
    6

    输出#1

    2 1 3
    3 6 2 5 1 4

说明/提示

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

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

  • p2=6=4⊕2=p6⊕2p_2 = 6 = 4 \oplus 2 = p_6 \oplus 2
  • p3=2=1⊕3=p5⊕3p_3 = 2 = 1 \oplus 3 = p_5 \oplus 3
  • p4=5=1⊕4=p5⊕4p_4 = 5 = 1 \oplus 4 = p_5 \oplus 4
  • p5=1=4⊕5=p6⊕5p_5 = 1 = 4 \oplus 5 = p_6 \oplus 5

在第一个测试用例中,排列 p=[2,1,3]p = [2,1,3] 是满足条件的,因为 p2=1p_2 = 1 且 p3⊕2=1p_3 \oplus 2 = 1。

在第二个测试用例中,排列 p=[3,6,2,5,1,4]p = [3,6,2,5,1,4] 是满足条件的,因为:

  • p2=6=4⊕2=p6⊕2p_2 = 6 = 4 \oplus 2 = p_6 \oplus 2
  • p3=2=1⊕3=p5⊕3p_3 = 2 = 1 \oplus 3 = p_5 \oplus 3
  • p4=5=1⊕4=p5⊕4p_4 = 5 = 1 \oplus 4 = p_5 \oplus 4
  • p5=1=4⊕5=p6⊕5p_5 = 1 = 4 \oplus 5 = p_6 \oplus 5

输入解题思路,AI测评打分。不知道怎么写?

首页