codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

2245C.md (2833B)


      1 Source: https://codeforces.com/problemset/problem/2245/C
      2 
      3 C. MEXOR
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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:
     22 
     23 * 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](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
     24 
     25 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).
     26 
     27 $^{\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$.
     28 
     29 Input
     30 
     31 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.
     32 
     33 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$).
     34 
     35 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
     36 
     37 Output
     38 
     39 For each test case, if no such permutation exists, output "NO".
     40 
     41 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.
     42 
     43 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.
     44 
     45 Example
     46 
     47 Input
     48 
     49 ```
     50 6
     51 
     52 1 0
     53 
     54 1 1
     55 
     56 3 0
     57 
     58 4 8
     59 
     60 5 1
     61 
     62 9 12
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 NO
     69 
     70 YES
     71 
     72 0
     73 
     74 YES
     75 
     76 0 1 2
     77 
     78 NO
     79 
     80 YES
     81 
     82 3 0 2 1 4
     83 
     84 YES
     85 
     86 1 4 0 8 2 3 7 5 6
     87 ```
     88 
     89 Note
     90 
     91 In the first and second test cases, the only permutation of length $1$ is $[0]$, with $f(0)=\operatorname{mex}([0])=1$.
     92 
     93 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$.
     94 
     95 In the fifth test case, the values of $f(i)$ for $0 \le i \lt n$ are as follows:
     96 
     97 * $f(0)=\operatorname{mex}([3])=0$,
     98 * $f(1)=\operatorname{mex}([3,0])=1$,
     99 * $f(2)=\operatorname{mex}([3,0,2])=1$,
    100 * $f(3)=\operatorname{mex}([3,0,2,1])=4$,
    101 * $f(4)=\operatorname{mex}([3,0,2,1,4])=5$,
    102 
    103 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.