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−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∗ 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 pi=pj⊕i †.
It can be proven that under the constraints of the problem, there exists at least one suitable permutation p.
∗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).
†⊕ denotes the bitwise XOR operation.
这是该问题的简单版本。两个版本的区别在于,在此版本中,2≤i≤n−1。请注意,困难版本的正确解法不一定适用于简单版本。
给定一个正整数 n。请构造一个长度为 n 的排列∗ p,使得对每个 i(\style{color:red}{2 \le i \le n-1}),均存在某个 j(\style{color:red}{i \le j \le n}),满足 pi=pj⊕i †。
在本题约束下,可以证明至少存在一个满足条件的排列 p。
∗ 长度为 n 的排列是指由 1 到 n 中互不相同的 n 个整数以任意顺序组成的数组。例如,[2,3,1,5,4] 是一个排列,而 [1,2,2] 不是排列(数字 2 在数组中出现了两次),[1,3,4] 也不是排列(此时 n=3,但数组中包含了 4)。
† ⊕ 表示按位异或运算。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The only line of each test case contains a single integer n (3≤n≤2⋅105) — the length of the permutation.
It is guaranteed that the sum of n across all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例仅一行,包含一个整数 n(3≤n≤2⋅105)—— 表示排列的长度。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, output n integers p1,p2,…,pn — the permutation p.
If there are multiple solutions, you may output any of them.
对于每个测试用例,输出 n 个整数 p1,p2,…,pn —— 即排列 p。
如果存在多个解,你可以输出其中任意一个。
输入输出样例
输入#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] is suitable since p2=1 and p3⊕2=1.
In the second test case, the permutation p=[3,6,2,5,1,4] is suitable, as:
- p2=6=4⊕2=p6⊕2
- p3=2=1⊕3=p5⊕3
- p4=5=1⊕4=p5⊕4
- p5=1=4⊕5=p6⊕5
在第一个测试用例中,排列 p=[2,1,3] 是满足条件的,因为 p2=1 且 p3⊕2=1。
在第二个测试用例中,排列 p=[3,6,2,5,1,4] 是满足条件的,因为:
- p2=6=4⊕2=p6⊕2
- p3=2=1⊕3=p5⊕3
- p4=5=1⊕4=p5⊕4
- p5=1=4⊕5=p6⊕5
输入解题思路,AI测评打分。不知道怎么写?