#P9033. 「KDOI-04」XOR Sum

    ID: 9974 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>洛谷原创Special JudgeO2优化构造洛谷月赛

「KDOI-04」XOR Sum

Background

Kevin solved this problem at a glance.

Problem Description

Given a positive integer nn, construct a sequence a1,a2,…,ana_1,a_2,\dots,a_n of length nn consisting of non-negative integers, such that:

  • For all 1≤i≤n1\le i\le n, we have 0≤ai≤m0\le a_i\le m.
  • a1⊕a2⊕⋯⊕an=ka_1\oplus a_2\oplus\dots\oplus a_n=k, where ⊕\oplus denotes the bitwise XOR operation.

Or determine that no such sequence exists.

Input Format

This problem contains multiple test cases.

The first line of the input contains a positive integer TT, denoting the number of test cases.

For each test case, the input contains one line with three non-negative integers n,k,mn,k,m.

Output Format

For each test case, output one line with −1-1 to indicate that no such sequence exists.

Otherwise, output nn non-negative integers separated by spaces, representing the sequence you construct. If there are multiple valid answers, you only need to output any one of them.

5
1 2 2
2 3 10
2 11 8
20 200000 99999
11 191 9810
2 
4 7 
8 3 
-1
191 191 191 191 191 191 191 191 191 191 191 

Hint

[Sample Explanation]

For the 11st test case, there is one and only one sequence that satisfies the conditions.

For the 22nd test case, since 4⊕7=34\oplus 7=3 and 4,7≤104,7\le10, this is a valid answer. Similarly, the sequence (2,1)(2,1) is also a valid answer.

For the 44th test case, it can be proven that there is no sequence that meets the requirements.

[Constraints]

Let ∑n\sum n be the sum of all nn values within a single test point.

For all testdata, it is guaranteed that 1≤T≤1 0001\le T\le 1~000, 1≤n≤2⋅1051\le n\le 2\cdot10^5, 0≤m,k≤1080\le m,k\le 10^8, and ∑n≤2⋅105\sum n\le 2\cdot10^5.

[Subtasks]

This problem uses bundled test cases.

  • Subtask 1 (18 pts): k≤mk\le m.
  • Subtask 2 (82 pts): No additional constraints.

Translated by ChatGPT 5