CF2245C.MEXOR
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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)=mex([p0,p1,…,pi])∗ for every 0≤i<n. Then, f(0)⊕f(1)⊕…⊕f(n−1) should equal k, where ⊕ 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).
∗The minimum excluded (MEX) of a collection of integers c1,c2,…,ck is defined as the smallest non-negative integer x which does not occur in the collection c.
给你一个正整数 n 和一个非负整数 k。请构造一个长度为 n 的排列 p,使得以下条件成立:
- 对每个 0≤i<n,令 f(i)=mex([p0,p1,…,pi])∗。那么,f(0)⊕f(1)⊕…⊕f(n−1) 应等于 k,其中 ⊕ 表示按位异或运算。
注意:长度为 n 的排列是指由 0 到 n−1 这 n 个互不相同的整数以任意顺序组成的数组。例如,[1,2,0,4,3] 是一个排列,但 [0,1,1] 不是排列(数组中 1 出现了两次),[0,2,3] 也不是排列(此时 n=3,但数组中出现了 3)。
∗ 一组整数 c1,c2,…,ck 的最小未出现值(MEX)定义为不在该集合 c 中的最小非负整数 x。
输入格式
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 two integers n and k (1≤n≤2⋅105, 0≤k≤109).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例仅有一行,包含两个整数 n 和 k(1≤n≤2⋅105,0≤k≤109)。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, if no such permutation exists, output "NO".
Otherwise, first output "YES" on a single line. Then, output n distinct integers p0,p1,…,pn−1 (0≤pi<n), representing the permutation p you constructed. If there are multiple permutations satisfying the requirement, you may output any of them.
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.
对于每个测试用例,若不存在满足条件的排列,则输出 "NO"。
否则,首先在单独一行输出 "YES";然后输出 n 个互不相同的整数 p0,p1,…,pn−1(其中 0≤pi<n),表示你构造出的排列 p。若存在多个满足要求的排列,输出任意一个即可。
你可以以任意大小写形式输出答案(例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均会被识别为肯定回答)。
输入输出样例
输入#1
6 1 0 1 1 3 0 4 8 5 1 9 12
输出#1
NO YES 0 YES 0 1 2 NO YES 3 0 2 1 4 YES 1 4 0 8 2 3 7 5 6
说明/提示
In the first and second test cases, the only permutation of length 1 is [0], with f(0)=mex([0])=1.
In the fourth test case, it can be proven that no permutation of length 4 exists such that f(0)⊕f(1)⊕f(2)⊕f(3)=8.
In the fifth test case, the values of f(i) for 0≤i<n are as follows:
- f(0)=mex([3])=0,
- f(1)=mex([3,0])=1,
- f(2)=mex([3,0,2])=1,
- f(3)=mex([3,0,2,1])=4,
- f(4)=mex([3,0,2,1,4])=5,
Since f(0)⊕f(1)⊕f(2)⊕f(3)⊕f(4)=0⊕1⊕1⊕4⊕5=1, p=[3,0,2,1,4] is a valid permutation.
在第一和第二个测试用例中,唯一长度为 1 的排列是 [0],此时 f(0)=mex([0])=1。
在第四个测试用例中,可以证明:不存在长度为 4 的排列,使得 f(0)⊕f(1)⊕f(2)⊕f(3)=8。
在第五个测试用例中,对所有满足 0≤i<n 的 i,f(i) 的值如下:
- f(0)=mex([3])=0,
- f(1)=mex([3,0])=1,
- f(2)=mex([3,0,2])=1,
- f(3)=mex([3,0,2,1])=4,
- f(4)=mex([3,0,2,1,4])=5,
由于 f(0)⊕f(1)⊕f(2)⊕f(3)⊕f(4)=0⊕1⊕1⊕4⊕5=1,因此排列 p=[3,0,2,1,4] 是一个合法的排列。
输入解题思路,AI测评打分。不知道怎么写?