CF1787E.The Harmonization of XOR

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array of exactly nn numbers [1,2,3,…,n][1,2,3,\ldots,n] along with integers kk and xx.

Partition the array in exactly kk non-empty disjoint subsequences such that the bitwise XOR of all numbers in each subsequence is xx, and each number is in exactly one subsequence. Notice that there are no constraints on the length of each subsequence.

A sequence aa is a subsequence of a sequence bb if aa can be obtained from bb by the deletion of several (possibly, zero or all) elements.

For example, for n=15n = 15, k=6k = 6, x=7x = 7, the following scheme is valid:

  • [6,10,11][6,10,11], 6⊕10⊕11=76 \oplus 10 \oplus 11 = 7,
  • [5,12,14][5,12,14], 5⊕12⊕14=75 \oplus 12 \oplus 14 = 7,
  • [3,9,13][3,9,13], 3⊕9⊕13=73 \oplus 9 \oplus 13 = 7,
  • [1,2,4][1,2,4], 1⊕2⊕4=71 \oplus 2 \oplus 4 = 7,
  • [8,15][8,15], 8⊕15=78 \oplus 15 = 7,
  • [7][7], 7=77 = 7,

where ⊕\oplus represents the bitwise XOR operation.

The following scheme is invalid, since 88, 1515 do not appear:

  • [6,10,11][6,10,11], 6⊕10⊕11=76 \oplus 10 \oplus 11 = 7,
  • [5,12,14][5,12,14], 5⊕12⊕14=75 \oplus 12 \oplus 14 = 7,
  • [3,9,13][3,9,13], 3⊕9⊕13=73 \oplus 9 \oplus 13 = 7,
  • [1,2,4][1,2,4], 1⊕2⊕4=71 \oplus 2 \oplus 4 = 7,
  • [7][7], 7=77 = 7.

The following scheme is invalid, since 33 appears twice, and 11, 22 do not appear:

  • [6,10,11][6,10,11], 6⊕10⊕11=76 \oplus 10 \oplus 11 = 7,
  • [5,12,14][5,12,14], 5⊕12⊕14=75 \oplus 12 \oplus 14 = 7,
  • [3,9,13][3,9,13], 3⊕9⊕13=73 \oplus 9 \oplus 13 = 7,
  • [3,4][3,4], 3⊕4=73 \oplus 4 = 7,
  • [8,15][8,15], 8⊕15=78 \oplus 15 = 7,
  • [7][7], 7=77 = 7.

你将得到一个恰好包含 nn 个数的数组 [1,2,3,…,n][1,2,3,\ldots,n],以及整数 kk 和 xx。

请将该数组恰好划分为 kk 个非空、互不相交的子序列,使得每个子序列中所有数的按位异或(XOR)结果均为 xx,且每个数恰好出现在一个子序列中。注意:对各个子序列的长度没有限制。

若序列 aa 可通过从序列 bb 中删除若干(可能为零个或全部)元素得到,则称 aa 是 bb 的一个子序列。

例如,当 n=15n = 15、k=6k = 6、x=7x = 7 时,如下划分是合法的:

  • [6,10,11][6,10,11],6⊕10⊕11=76 \oplus 10 \oplus 11 = 7,
  • [5,12,14][5,12,14],5⊕12⊕14=75 \oplus 12 \oplus 14 = 7,
  • [3,9,13][3,9,13],3⊕9⊕13=73 \oplus 9 \oplus 13 = 7,
  • [1,2,4][1,2,4],1⊕2⊕4=71 \oplus 2 \oplus 4 = 7,
  • [8,15][8,15],8⊕15=78 \oplus 15 = 7,
  • [7][7],7=77 = 7,

其中 ⊕\oplus 表示按位异或运算。

如下划分是非法的,因为 88 和 1515 未出现:

  • [6,10,11][6,10,11],6⊕10⊕11=76 \oplus 10 \oplus 11 = 7,
  • [5,12,14][5,12,14],5⊕12⊕14=75 \oplus 12 \oplus 14 = 7,
  • [3,9,13][3,9,13],3⊕9⊕13=73 \oplus 9 \oplus 13 = 7,
  • [1,2,4][1,2,4],1⊕2⊕4=71 \oplus 2 \oplus 4 = 7,
  • [7][7],7=77 = 7。

如下划分也是非法的,因为 33 出现了两次,而 11、22 未出现:

  • [6,10,11][6,10,11],6⊕10⊕11=76 \oplus 10 \oplus 11 = 7,
  • [5,12,14][5,12,14],5⊕12⊕14=75 \oplus 12 \oplus 14 = 7,
  • [3,9,13][3,9,13],3⊕9⊕13=73 \oplus 9 \oplus 13 = 7,
  • [3,4][3,4],3⊕4=73 \oplus 4 = 7,
  • [8,15][8,15],8⊕15=78 \oplus 15 = 7,
  • [7][7],7=77 = 7。

输入格式

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first and the only line of each test case contains three integers nn, kk, xx (1≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5; 1≤x≤1091\le x \le 10^9) — the length of the array, the number of subsequences and the required XOR.

It's guaranteed that the sum of nn does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例仅有一行,包含三个整数 nn、kk、xx(1≤k≤n≤2⋅1051 \le k \le n \le 2 \cdot 10^5;1≤x≤1091\le x \le 10^9)—— 分别表示数组长度、子序列数量以及目标异或值。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, if it is possible to partition the sequence, print "YES" in the first line. In the ii-th of the following kk lines first print the length sis_i of the ii-th subsequence, then print sis_i integers, representing the elements in the ii-th subsequence. If there are multiple answers, print any. Note that you can print a subsequence in any order.

If it is not possible to partition the sequence, print "NO".

对于每个测试用例,如果可以将序列划分为若干子序列,则在第一行输出 "YES"。接下来的 kk 行中,第 ii 行首先输出第 ii 个子序列的长度 sis_i,然后输出 sis_i 个整数,表示该子序列中的元素。若存在多种可行方案,输出任意一种即可。注意:每个子序列中的元素顺序可以任意。

如果无法划分该序列,则输出 "NO"。

输入输出样例

  • 输入#1

    7
    15 6 7
    11 4 5
    5 3 2
    4 1 4
    6 1 7
    11 5 5
    11 6 5

    输出#1

    YES
    3 6 10 11
    3 5 12 14
    3 3 9 13
    3 1 2 4
    2 8 15
    1 7
    YES
    2 1 4
    2 2 7
    2 3 6
    5 5 8 9 10 11
    NO
    YES
    4 1 2 3 4
    YES
    6 1 2 3 4 5 6
    NO
    NO

说明/提示

In the first test case, we construct the following 66 subsequences:

  • [6,10,11][6,10,11], 6⊕10⊕11=76 \oplus 10 \oplus 11 = 7,
  • [5,12,14][5,12,14], 5⊕12⊕14=75 \oplus 12 \oplus 14 = 7,
  • [3,9,13][3,9,13], 3⊕9⊕13=73 \oplus 9 \oplus 13 = 7,
  • [1,2,4][1,2,4], 1⊕2⊕4=71 \oplus 2 \oplus 4 = 7,
  • [8,15][8,15], 8⊕15=78 \oplus 15 = 7,
  • [7][7], 7=77 = 7.

In the second test case, we construct the following 44 subsequences:

  • [1,4][1,4], 1⊕4=51 \oplus 4 = 5,
  • [2,7][2,7], 2⊕7=52 \oplus 7 = 5,
  • [3,6][3,6], 3⊕6=53 \oplus 6 = 5,
  • [5,8,9,10,11][5,8,9,10,11], 5⊕8⊕9⊕10⊕11=55 \oplus 8 \oplus 9 \oplus 10 \oplus 11 = 5.

The following solution is considered correct in this test case as well:

  • [1,4][1,4], 1⊕4=51 \oplus 4 = 5,
  • [2,7][2,7], 2⊕7=52 \oplus 7 = 5,
  • [5][5], 5=55 = 5,
  • [3,6,8,9,10,11][3,6,8,9,10,11], 3⊕6⊕8⊕9⊕10⊕11=53 \oplus 6 \oplus 8 \oplus 9 \oplus 10 \oplus 11 = 5.

在第一个测试用例中,我们构造了以下 66 个子序列:

  • [6,10,11][6,10,11],6⊕10⊕11=76 \oplus 10 \oplus 11 = 7,
  • [5,12,14][5,12,14],5⊕12⊕14=75 \oplus 12 \oplus 14 = 7,
  • [3,9,13][3,9,13],3⊕9⊕13=73 \oplus 9 \oplus 13 = 7,
  • [1,2,4][1,2,4],1⊕2⊕4=71 \oplus 2 \oplus 4 = 7,
  • [8,15][8,15],8⊕15=78 \oplus 15 = 7,
  • [7][7],7=77 = 7。

在第二个测试用例中,我们构造了以下 44 个子序列:

  • [1,4][1,4],1⊕4=51 \oplus 4 = 5,
  • [2,7][2,7],2⊕7=52 \oplus 7 = 5,
  • [3,6][3,6],3⊕6=53 \oplus 6 = 5,
  • [5,8,9,10,11][5,8,9,10,11],5⊕8⊕9⊕10⊕11=55 \oplus 8 \oplus 9 \oplus 10 \oplus 11 = 5。

以下解法在此测试用例中也被视为正确:

  • [1,4][1,4],1⊕4=51 \oplus 4 = 5,
  • [2,7][2,7],2⊕7=52 \oplus 7 = 5,
  • [5][5],5=55 = 5,
  • [3,6,8,9,10,11][3,6,8,9,10,11],3⊕6⊕8⊕9⊕10⊕11=53 \oplus 6 \oplus 8 \oplus 9 \oplus 10 \oplus 11 = 5。

输入解题思路,AI测评打分。不知道怎么写?

首页