#P13551. ももいろの鍵

    ID: 11913 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>洛谷原创Special JudgeO2优化位运算构造洛谷月赛

ももいろの鍵

Description

You are given a non-negative integer nn. You need to partition the numbers 0,1,2,,n0, 1, 2, \dots, n into several groups such that the bitwise AND of all numbers in each group is 00.

Your goal is to maximize the number of groups and provide a valid partitioning scheme.

Input Format

This problem contains multiple test cases in a single test point.

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

For each test case, the input is formatted as follows:

  • One line containing a non-negative integer nn.

Output Format

For each test case, first output a positive integer ansans, representing the maximum number of groups.

Then, output ansans lines. Each line should start with a positive integer kk, indicating the size of the current group, followed by kk integers representing the elements in the group.

If there are multiple optimal partitioning schemes, you may output any of them.

4
0
1
2
3

1
1 0
1
2 0 1
2
2 2 1
1 0
2
2 1 2
2 0 3

Hint

Subtask Points nn \le Special Constraints
11 1010 1010 None
22 2020
33 1515 10510^5 n,k0,kN,n=2k1\forall n,\exists k \geq 0,k \in \N, n=2^k-1
44 100100 None
55 500500
66 3535 10510^5

For all test cases, it is guaranteed that 1T6001 \le T \le 600, 0n1050 \le n \le 10^5, and the sum of nn across all test cases in a single test point does not exceed 2×1052 \times 10^5.

Generated by Deepseek V3.