异或和的最小值AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given a positive integer $N$.
给定一个正整数 $N$。AI (CI翻译)
Find one permutation $P=(P_1,P_2,\ldots,P_N)$ of $(1,2,\ldots,N)$ that minimizes $\displaystyle \sum_{i=1}^N \bigoplus_{1\le j\le i} P_j$.
请找出 $(1,2,\ldots,N)$ 的一个排列 $P=(P_1,P_2,\ldots,P_N)$,使得 $\displaystyle \sum_{i=1}^N \bigoplus_{1\le j\le i} P_j$ 最小。AI (CI翻译)
Here, $\displaystyle \bigoplus_{1\le j\le i} P_j$ is defined as the bitwise $\mathrm{XOR}$ of $P_1,P_2,\ldots,P_i$.
其中,$\displaystyle \bigoplus_{1\le j\le i} P_j$ 定义为 $P_1,P_2,\ldots,P_i$ 的按位 $mathrm{XOR}$。AI (CI翻译)
You are given $T$ test cases; solve each of them.
给定 $T$ 组测试用例,请分别求解每组测试用例。AI (CI翻译)
What is bitwise $\mathrm{XOR}$? The bitwise $\mathrm{XOR}$ of non-negative integers $A$ and $B$, $A \oplus B$, is defined as follows. In the binary representation of $A \oplus B$, the digit at the $2^k$ ($k \geq 0$) place is $1$ if exactly one of the digits at the $2^k$ place in the binary representations of $A$ and $B$ is $1$, and $0$ otherwise. For example, $3 \oplus 5 = 6$ (in binary: $011 \oplus 101 = 110$). In general, the bitwise $\mathrm{XOR}$ of $k$ non-negative integers $p_1, p_2, p_3, \dots, p_k$ is defined as $(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k)$, and it can be proved that this does not depend on the order of $p_1, p_2, p_3, \dots, p_k$.
什么是按位 $mathrm{XOR}$?对于非负整数 $A$ 和 $B$,按位 $mathrm{XOR}$ $A \oplus B$ 的定义如下:在 $A \oplus B$ 的二进制表示中,$2^k$($k \geq 0$)位上的数字,当且仅当 $A$ 和 $B$ 的二进制表示中 $2^k$ 位上的数字恰有一个为 $1$ 时为 $1$,否则为 $0$。例如,$3 \oplus 5 = 6$(二进制表示为:$011 \oplus 101 = 110$)。一般来说,$k$ 个非负整数 $p_1, p_2, p_3, \dots, p_k$ 的按位 $mathrm{XOR}$ 定义为 $(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k)$,可以证明其结果与 $p_1,p_2,p_3,\dots,p_k$ 的排列顺序无关。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1\le T\le 10^3$$1\le N$- The sum of
$N$over all test cases is at most$2\times 10^5$. - All input values are integers.
$1\le T\le 10^3$$1\le N$- 所有测试用例的
$N$之和不超过$2\times 10^5$。 - 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_TAI (CI翻译)
Each test case is given in the following format:
每组测试用例按以下格式给出:AI (CI翻译)
N
NAI (CI翻译)
Output
输出格式
AI (CI翻译)Output the answers for the test cases in order, separated by newlines.
按测试用例的顺序输出答案,每组答案之间用换行分隔。AI (CI翻译)
For each test case, output a permutation $P=(P_1,P_2,\ldots,P_N)$ of $(1,2,\ldots,N)$ that minimizes $\displaystyle \sum_{i=1}^N \bigoplus_{1\le j\le i} P_j$, separated by spaces.
对于每组测试用例,输出一个 $(1,2,\ldots,N)$ 的排列 $P=(P_1,P_2,\ldots,P_N)$,使得 $\displaystyle \sum_{i=1}^N \bigoplus_{1\le j\le i} P_j$ 最小,排列中的元素之间用空格分隔。AI (CI翻译)
If there are multiple permutations $P$ that achieve the minimum, any of them will be accepted.
如果有多个排列 $P$ 能够取得最小值,输出其中任意一个均可。AI (CI翻译)
样例
3
3
1
7
1 3 2
1
4 5 3 2 6 7 1
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。