MEXORAI (CI翻译)
You are given a positive integer $n$ and a non-negative integer $k$. Construct a permutation $p$ of length $n$ such that the following condition is satisfied:
- Let
$f(i)=\operatorname{mex}([p_0,p_1,\ldots,p_i])$$^{\text{∗}}$for every$0 \le i \lt n$. Then,$f(0) \oplus f(1) \oplus \ldots \oplus f(n-1)$should equal$k$, where$\oplus$denotes the bitwise XOR operation.
Note that a permutation of length $n$ is an array consisting of $n$ distinct integers from $0$ to $n-1$ in arbitrary order. For example, $[1,2,0,4,3]$ is a permutation, but $[0,1,1]$ is not a permutation ($1$ appears twice in the array), and $[0,2,3]$ is also not a permutation ($n=3$ but there is $3$ in the array).
$^{\text{∗}}$The minimum excluded (MEX) of a collection of integers $c_1, c_2, \ldots, c_k$ is defined as the smallest non-negative integer $x$ which does not occur in the collection $c$.
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
每个测试包含多个测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)
The only line of each test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $0 \le k \le 10^9$).
每个测试用例仅包含一行,包含两个整数 $n$ 和 $k$($1 \le n \le 2 \cdot 10^5$,$0 \le k \le 10^9$)。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, if no such permutation exists, output "NO".
对于每个测试用例,如果不存在满足条件的排列,输出“NO”。AI (CI翻译)
Otherwise, first output "YES" on a single line. Then, output $n$ distinct integers $p_0,p_1,\ldots,p_{n-1}$ ($0 \le p_i \lt n$), representing the permutation $p$ you constructed. If there are multiple permutations satisfying the requirement, you may output any of them.
否则,首先在单独一行输出“YES”。然后输出 $n$ 个互不相同的整数 $p_0,p_1,\ldots,p_{n-1}$($0 \le p_i \lt n$),表示你构造的排列 $p$。如果有多个排列满足要求,你可以输出其中任意一个。AI (CI翻译)
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
你可以使用任意大小写形式输出答案。例如,字符串“yEs”“yes”“Yes”和“YES”都会被识别为肯定回答。AI (CI翻译)
Note
说明
AI (CI翻译)In the first and second test cases, the only permutation of length $1$ is $[0]$, with $f(0)=\operatorname{mex}([0])=1$.
在第一个和第二个测试用例中,长度为 $1$ 的排列只有 $[0]$,且 $f(0)=\operatorname{mex}([0])=1$。AI (CI翻译)
In the fourth test case, it can be proven that no permutation of length $4$ exists such that $f(0) \oplus f(1) \oplus f(2) \oplus f(3)=8$.
在第四个测试用例中,可以证明不存在长度为 $4$ 的排列,使得 $f(0) \oplus f(1) \oplus f(2) \oplus f(3)=8$。AI (CI翻译)
In the fifth test case, the values of $f(i)$ for $0 \le i \lt n$ are as follows:
在第五个测试用例中,对于 $0 \le i \lt n$,$f(i)$ 的值如下:AI (CI翻译)
$f(0)=\operatorname{mex}([3])=0$,$f(1)=\operatorname{mex}([3,0])=1$,$f(2)=\operatorname{mex}([3,0,2])=1$,$f(3)=\operatorname{mex}([3,0,2,1])=4$,$f(4)=\operatorname{mex}([3,0,2,1,4])=5$,
$f(0)=\operatorname{mex}([3])=0$,$f(1)=\operatorname{mex}([3,0])=1$,$f(2)=\operatorname{mex}([3,0,2])=1$,$f(3)=\operatorname{mex}([3,0,2,1])=4$,$f(4)=\operatorname{mex}([3,0,2,1,4])=5$,
Since $f(0) \oplus f(1) \oplus f(2) \oplus f(3) \oplus f(4)=0\oplus 1 \oplus 1 \oplus 4 \oplus 5=1$, $p=[3,0,2,1,4]$ is a valid permutation.
由于 $f(0) \oplus f(1) \oplus f(2) \oplus f(3) \oplus f(4)=0\oplus 1 \oplus 1 \oplus 4 \oplus 5=1$,因此 $p=[3,0,2,1,4]$ 是一个合法的排列。AI (CI翻译)
样例
6
1 0
1 1
3 0
4 8
5 1
9 12
NO
YES
0
YES
0 1 2
NO
YES
3 0 2 1 4
YES
1 4 0 8 2 3 7 5 6
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。