CF2245C.MEXOR

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a positive integer nn and a non-negative integer kk. Construct a permutation pp of length nn such that the following condition is satisfied:

  • Let f(i)=mex⁡([p0,p1,…,pi])f(i)=\operatorname{mex}([p_0,p_1,\ldots,p_i])∗^{\text{∗}} for every 0≤i<n0 \le i \lt n. Then, f(0)⊕f(1)⊕…⊕f(n−1)f(0) \oplus f(1) \oplus \ldots \oplus f(n-1) should equal kk, where ⊕\oplus denotes the bitwise XOR operation.

Note that a permutation of length nn is an array consisting of nn distinct integers from 00 to n−1n-1 in arbitrary order. For example, [1,2,0,4,3][1,2,0,4,3] is a permutation, but [0,1,1][0,1,1] is not a permutation (11 appears twice in the array), and [0,2,3][0,2,3] is also not a permutation (n=3n=3 but there is 33 in the array).

∗^{\text{∗}}The minimum excluded (MEX) of a collection of integers c1,c2,…,ckc_1, c_2, \ldots, c_k is defined as the smallest non-negative integer xx which does not occur in the collection cc.

给你一个正整数 nn 和一个非负整数 kk。请构造一个长度为 nn 的排列 pp,使得以下条件成立:

  • 对每个 0≤i<n0 \le i \lt n,令 f(i)=mex⁡([p0,p1,…,pi])f(i)=\operatorname{mex}([p_0,p_1,\ldots,p_i])∗^{\text{∗}}。那么,f(0)⊕f(1)⊕…⊕f(n−1)f(0) \oplus f(1) \oplus \ldots \oplus f(n-1) 应等于 kk,其中 ⊕\oplus 表示按位异或运算。

注意:长度为 nn 的排列是指由 00 到 n−1n-1 这 nn 个互不相同的整数以任意顺序组成的数组。例如,[1,2,0,4,3][1,2,0,4,3] 是一个排列,但 [0,1,1][0,1,1] 不是排列(数组中 11 出现了两次),[0,2,3][0,2,3] 也不是排列(此时 n=3n=3,但数组中出现了 33)。

∗^{\text{∗}} 一组整数 c1,c2,…,ckc_1, c_2, \ldots, c_k 的最小未出现值(MEX)定义为不在该集合 cc 中的最小非负整数 xx。

输入格式

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 two integers nn and kk (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 0≤k≤1090 \le k \le 10^9).

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

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

每个测试用例仅有一行,包含两个整数 nn 和 kk(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,0≤k≤1090 \le k \le 10^9)。

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

输出格式

For each test case, if no such permutation exists, output "NO".

Otherwise, first output "YES" on a single line. Then, output nn distinct integers p0,p1,…,pn−1p_0,p_1,\ldots,p_{n-1} (0≤pi<n0 \le p_i \lt n), representing the permutation pp 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";然后输出 nn 个互不相同的整数 p0,p1,…,pn−1p_0,p_1,\ldots,p_{n-1}(其中 0≤pi<n0 \le p_i \lt n),表示你构造出的排列 pp。若存在多个满足要求的排列,输出任意一个即可。

你可以以任意大小写形式输出答案(例如,字符串 "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 11 is [0][0], with f(0)=mex⁡([0])=1f(0)=\operatorname{mex}([0])=1.

In the fourth test case, it can be proven that no permutation of length 44 exists such that f(0)⊕f(1)⊕f(2)⊕f(3)=8f(0) \oplus f(1) \oplus f(2) \oplus f(3)=8.

In the fifth test case, the values of f(i)f(i) for 0≤i<n0 \le i \lt n are as follows:

  • f(0)=mex⁡([3])=0f(0)=\operatorname{mex}([3])=0,
  • f(1)=mex⁡([3,0])=1f(1)=\operatorname{mex}([3,0])=1,
  • f(2)=mex⁡([3,0,2])=1f(2)=\operatorname{mex}([3,0,2])=1,
  • f(3)=mex⁡([3,0,2,1])=4f(3)=\operatorname{mex}([3,0,2,1])=4,
  • f(4)=mex⁡([3,0,2,1,4])=5f(4)=\operatorname{mex}([3,0,2,1,4])=5,

Since f(0)⊕f(1)⊕f(2)⊕f(3)⊕f(4)=0⊕1⊕1⊕4⊕5=1f(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]p=[3,0,2,1,4] is a valid permutation.

在第一和第二个测试用例中,唯一长度为 11 的排列是 [0][0],此时 f(0)=mex⁡([0])=1f(0)=\operatorname{mex}([0])=1。

在第四个测试用例中,可以证明:不存在长度为 44 的排列,使得 f(0)⊕f(1)⊕f(2)⊕f(3)=8f(0) \oplus f(1) \oplus f(2) \oplus f(3)=8。

在第五个测试用例中,对所有满足 0≤i<n0 \le i \lt n 的 ii,f(i)f(i) 的值如下:

  • f(0)=mex⁡([3])=0f(0)=\operatorname{mex}([3])=0,
  • f(1)=mex⁡([3,0])=1f(1)=\operatorname{mex}([3,0])=1,
  • f(2)=mex⁡([3,0,2])=1f(2)=\operatorname{mex}([3,0,2])=1,
  • f(3)=mex⁡([3,0,2,1])=4f(3)=\operatorname{mex}([3,0,2,1])=4,
  • f(4)=mex⁡([3,0,2,1,4])=5f(4)=\operatorname{mex}([3,0,2,1,4])=5,

由于 f(0)⊕f(1)⊕f(2)⊕f(3)⊕f(4)=0⊕1⊕1⊕4⊕5=1f(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]p=[3,0,2,1,4] 是一个合法的排列。

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

首页