CF1726B.Mainak and Interesting Sequence
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Mainak has two positive integers n and m.
Mainak finds a sequence a1,a2,…,an of n positive integers interesting, if for all integers i (1≤i≤n), the bitwise XOR of all elements in a which are strictly less than ai is 0. Formally if pi is the bitwise XOR of all elements in a which are strictly less than ai, then a is an interesting sequence if p1=p2=…=pn=0.
For example, sequences [1,3,2,3,1,2,3], [4,4,4,4], [25] are interesting, whereas [1,2,3,4] (p2=1=0), [4,1,1,2,4] (p1=1⊕1⊕2=2=0), [29,30,30] (p2=29=0) aren't interesting.
Here a⊕b denotes bitwise XOR of integers a and b.
Find any interesting sequence a1,a2,…,an (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. a1+a2…+an=m.
As a reminder, the bitwise XOR of an empty sequence is considered to be 0.
Mainak 有两个正整数 n 和 m。
Mainak 将一个由 n 个正整数组成的序列 a1,a2,…,an 称为有趣的序列,当且仅当对所有整数 i(1≤i≤n),序列 a 中所有严格小于 ai 的元素的按位异或结果为 0。形式化地,若记 pi 为序列 a 中所有严格小于 ai 的元素的按位异或值,则当且仅当 p1=p2=…=pn=0 时,序列 a 是有趣的。
例如,序列 [1,3,2,3,1,2,3]、[4,4,4,4]、[25] 是有趣的;而序列 [1,2,3,4](因为 p2=1=0)、[4,1,1,2,4](因为 p1=1⊕1⊕2=2=0)、[29,30,30](因为 p2=29=0)则不是有趣的。
此处 a⊕b 表示整数 a 与 b 的按位异或。
请构造任意一个有趣的序列 a1,a2,…,an(若不存在则报告无解),使得该序列中所有元素之和等于 m,即满足 a1+a2+…+an=m。
提醒:空序列的按位异或值定义为 0。
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤105) — the number of test cases. Description of the test cases follows.
The first line and the only line of each test case contains two integers n and m (1≤n≤105, 1≤m≤109) — the length of the sequence and the sum of the elements.
It is guaranteed that the sum of n over all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤105),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例仅有一行,包含两个整数 n 和 m(1≤n≤105,1≤m≤109),分别表示序列的长度和元素之和。
保证所有测试用例的 n 之和不超过 105。
输出格式
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).
If the answer is "Yes", output n positive integers a1,a2,…,an (ai≥1), forming an interesting sequence such that a1+a2…+an=m. If there are multiple solutions, output any.
对于每个测试用例,如果存在某个有趣的序列,则在第一行输出“Yes”;否则输出“No”。你可以以任意大小写形式输出每个字母(例如,“YES”、“Yes”、“yes”、“yEs”均会被识别为肯定回答)。
如果答案为“Yes”,则输出 n 个正整数 a1,a2,…,an(满足 ai≥1),构成一个有趣的序列,使得 a1+a2+…+an=m。若存在多个解,输出任意一个即可。
输入输出样例
输入#1
4 1 3 6 12 2 1 3 6
输出#1
Yes 3 Yes 1 3 2 2 3 1 No Yes 2 2 2
说明/提示
-
In the first test case, [3] is the only interesting sequence of length 1 having sum 3.
-
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.
-
In the fourth test case, p1=p2=p3=0, because bitwise XOR of an empty sequence is 0.
-
在第一个测试用例中,[3] 是唯一一个长度为 1 且元素和为 3 的有趣序列。
-
在第三个测试用例中,不存在长度为 2 且元素和等于 1 的序列,因此不存在这样的有趣序列。
-
在第四个测试用例中,p1=p2=p3=0,因为空序列的按位异或(bitwise XOR)值为 0。
输入解题思路,AI测评打分。不知道怎么写?