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$ 下列分法是不合法的: - $[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$ 因为 $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$, - $[3,4]$, $3 \oplus 4 = 7$, - $[8,15]$, $8 \oplus 15 = 7$, - $[7]$, $7 = 7$. 因为 $1$ 和 $2$ 未出现且 $3$ 出现两次。 ~~这题本来是 C~~ 保证所有测试数据的 $n$ 之和不超过 $2\cdot 10^5$。

输入格式

第一行一个正整数 $t$($1\le t\le 10^4$)表示测试数据组数。

输出格式

对于每组测试数据,若不存在合法方案,输出 `NO`。若存在,先输出 `YES`,接下来 $k$ 行输出方案。具体地,每一行第一个数字输出这一组的长度 $s_i$,后接 $s_i$ 个数字表示这一组的数字。注意每一组中的数字可以按任意顺序给出。 ### 样例解释 第一组测试数据中,给出的一组合法方案如下: - $[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$ 第二组测试数据中,给出的一组合法方案如下: - $[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$

说明/提示

In the first test case, we construct the following $ 6 $ subsequences: - $ [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 $ . In the second test case, we construct the following $ 4 $ subsequences: - $ [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 $ . The following solution is considered correct in this test case as well: - $ [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 $ .