CF1787E The Harmonization of XOR

题目描述

给定长度为 $n$ 的序列 $[1,2,3,\ldots,n]$ 和两个正整数 $k$ 和 $x$。 你要将这个序列划分为恰好 $k$ 个子序列,使得每个子序列中所有数的异或和均为 $x$,并且每个数都出现在恰好一个子序列中。注意每个子序列的长度没有限制。 例如,当 $n = 15,k = 6,x = 7$ 时,下列划分是合法的(其中 $\oplus$ 表示按位异或): - $[6,10,11]$, $6 \oplus 10 \oplus 11 = 7$, - $[5,12,14]$, $5 \oplus 12 \oplus 14 = 7$, - $[3,9,13]$, $3 \oplus 9 \oplus 13 = 7$, - $[1,2,4]$, $1 \oplus 2 \oplus 4 = 7$, - $[8,15]$, $8 \oplus 15 = 7$, - $[7]$, $7 = 7$。 下列划分是不合法的,因为 $8$ 和 $15$ 没有出现: - $[6,10,11]$, $6 \oplus 10 \oplus 11 = 7$, - $[5,12,14]$, $5 \oplus 12 \oplus 14 = 7$, - $[3,9,13]$, $3 \oplus 9 \oplus 13 = 7$, - $[1,2,4]$, $1 \oplus 2 \oplus 4 = 7$, - $[7]$, $7 = 7$。 下列分法也不合法,因为 $1$ 和 $2$ 未出现且 $3$ 出现两次: - $[6,10,11]$, $6 \oplus 10 \oplus 11 = 7$, - $[5,12,14]$, $5 \oplus 12 \oplus 14 = 7$, - $[3,9,13]$, $3 \oplus 9 \oplus 13 = 7$, - $[3,4]$, $3 \oplus 4 = 7$, - $[8,15]$, $8 \oplus 15 = 7$, - $[7]$, $7 = 7$。

输入格式

每个测试点包含多组测试数据。第一行包含一个正整数 $t$($1\le t\le 10^4$)表示测试数据组数。 每组测试数据占一行,包含三个正整数 $n,k,x$($1\le k\le n\le 2\cdot10^5$,$1\le x\le10^9$),分别表示序列的长度、子序列的数量和要求的异或和。 保证所有测试数据中 $n$ 的和不超过 $2\cdot10^5$。

输出格式

对于每组测试数据,如果不存在合法方案,输出 `NO`,否则在第一行输出 `YES`,并在接下来的 $k$ 行输出方案。其中的第 $i$ 行先输出一个正整数 $s_i$ 表示第 $i$ 个子序列的长度,接下来输出 $s_i$ 个数字表示第 $i$ 个子序列中的所有元素。注意每一个子序列中的数字可以按任意顺序输出。

说明/提示

### 样例解释 第一组测试数据中,我们构造以下 $6$ 个子序列: - $[6,10,11]$, $6 \oplus 10 \oplus 11 = 7$; - $[5,12,14]$, $5 \oplus 12 \oplus 14 = 7$; - $[3,9,13]$, $3 \oplus 9 \oplus 13 = 7$; - $[1,2,4]$, $1 \oplus 2 \oplus 4 = 7$; - $[8,15]$, $8 \oplus 15 = 7$; - $[7]$, $7 = 7$。 第二组测试数据中,我们构造以下 $4$ 个子序列: - $[1,4]$, $1 \oplus 4 = 5$; - $[2,7]$, $2 \oplus 7 = 5$; - $[3,6]$, $3 \oplus 6 = 5$; - $[5,8,9,10,11]$, $5 \oplus 8 \oplus 9 \oplus 10 \oplus 11 = 5$。 以下方案也被认为是合法的: - $[1,4]$, $1 \oplus 4 = 5$; - $[2,7]$, $2 \oplus 7 = 5$; - $[5]$, $5 = 5$; - $[3,6,8,9,10,11]$, $3 \oplus 6 \oplus 8 \oplus 9 \oplus 10 \oplus 11 = 5$。