P8468 [Aya Round 1 C] Wenwen’s Construction Game
Background
**Problem Number:** [$\textit{23}$](https://www.luogu.com.cn/training/1392)
As everyone knows, Shameimaru Aya and Cirno are good friends. However, Aya is a powerful youkai and very smart, while Cirno is a fool. To improve Cirno’s IQ, Aya gave Cirno a simple problem.
Description
For a sequence $p$ of length $l$, define $S(p)$ as the **bitwise XOR sum** of all elements, where $\oplus$ denotes the [bitwise XOR operation](https://baike.baidu.com/item/%E5%BC%82%E6%88%96%E6%93%8D%E4%BD%9C).
Given integers $s, m$, determine whether it is possible to construct a sequence $a$ of length $n$ (you may choose $n$) such that:
- $1 \le n \le m$.
- $1 \le a_i \le s$.
- $S(a) = 0$.
- $a_1 + a_2 + \cdots + a_n = s$.
Construct any valid solution, or report that no solution exists.
Input Format
**This problem contains multiple test cases.**
- The first line contains an integer $T$, the number of test cases.
- The next $T$ lines each contain two integers $s, m$, representing one query.
Output Format
- Output a total of $T$ lines.
- For each test case:
- If there is a solution, first output an integer $n$, then output $n$ integers representing $a$.
- If there is no solution, output a single integer $-1$ on one line.
Explanation/Hint
### Sample Explanation
- For test case $1$, it is easy to see that $3 \oplus 5 \oplus 6 = 0$ and $3 + 5 + 6 = 14$, which satisfies the requirements.
- For test case $2$, the sequences $\{3\}$, $\{1,2\}$, and $\{1,1,1\}$ all do not satisfy the requirements, so there is no solution.
### Constraints and Notes
For $100\%$ of the testdata, $1 \le s \le 10^{18}$, $1 \le m$, and $1 \le \sum m \le 10^6$.
**Friendly reminder: you may need to use faster I/O.**
Translated by ChatGPT 5