1726B.md (2617B)
1 Source: https://codeforces.com/problemset/problem/1726/B 2 3 B. Mainak and Interesting Sequence 4 5 time limit per test 6 7 1 second 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 Mainak has two positive integers $n$ and $m$. 22 23 Mainak finds a sequence $a_1, a_2, \ldots, a_n$ of $n$ positive integers interesting, if for all integers $i$ ($1 \le i \le n$), the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of all elements in $a$ which are strictly less than $a_i$ is $0$. Formally if $p_i$ is the bitwise XOR of all elements in $a$ which are strictly less than $a_i$, then $a$ is an interesting sequence if $p_1 = p_2 = \ldots = p_n = 0$. 24 25 For example, sequences $[1,3,2,3,1,2,3]$, $[4,4,4,4]$, $[25]$ are interesting, whereas $[1,2,3,4]$ ($p_2 = 1 \ne 0$), $[4,1,1,2,4]$ ($p_1 = 1 \oplus 1 \oplus 2 = 2 \ne 0$), $[29,30,30]$ ($p_2 = 29 \ne 0$) aren't interesting. 26 27 Here $a \oplus b$ denotes bitwise XOR of integers $a$ and $b$. 28 29 Find any interesting sequence $a_1, a_2, \ldots, a_n$ (or report that there exists no such sequence) such that the sum of the elements in the sequence $a$ is equal to $m$, i.e. $a_1 + a_2 \ldots + a_n = m$. 30 31 As a reminder, the bitwise XOR of an empty sequence is considered to be $0$. 32 33 Input 34 35 Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^5$) — the number of test cases. Description of the test cases follows. 36 37 The first line and the only line of each test case contains two integers $n$ and $m$ ($1 \le n \le 10^5$, $1 \le m \le 10^9$) — the length of the sequence and the sum of the elements. 38 39 It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. 40 41 Output 42 43 For each test case, if there exists some interesting sequence, output "Yes" on the first line, otherwise output "No". You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer). 44 45 If the answer is "Yes", output $n$ positive integers $a_1, a_2, \ldots, a_n$ ($a_i \ge 1$), forming an interesting sequence such that $a_1 + a_2 \ldots + a_n = m$. If there are multiple solutions, output any. 46 47 Example 48 49 Input 50 51 ``` 52 4 53 1 3 54 6 12 55 2 1 56 3 6 57 ``` 58 59 Output 60 61 ``` 62 Yes 63 3 64 Yes 65 1 3 2 2 3 1 66 No 67 Yes 68 2 2 2 69 ``` 70 71 Note 72 73 * In the first test case, $[3]$ is the only interesting sequence of length $1$ having sum $3$. 74 * In the third test case, there is no sequence of length $2$ having sum of elements equal to $1$, so there is no such interesting sequence. 75 * In the fourth test case, $p_1 = p_2 = p_3 = 0$, because bitwise XOR of an empty sequence is $0$.