| Codeforces Round 1133 (Div. 1) |
|---|
| Finished |
As you may know, the game of "Nim" is played with several piles of stones and two players alternating turns. During a turn, a player picks any non-empty pile and removes any positive number of stones from it; the one who is not able to make a move loses the game.
Alice wants to play Nim with the Mad Hatter on $$$n$$$ piles $$$s_1, s_2, \ldots, s_n$$$ with distinct positive number of stones, but they get bored because they've played the game too many times. Instead, Alice proposes the following variant:
Note that the input is given encoded; see the Input section for a description of it. Because of the encoding format, you will need to solve the given problem for each prefix $$$s_1, s_2, \ldots, s_i$$$. However, you will only output this coloring for the entire set of piles $$$s_1, s_2, \ldots, s_n$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 7000$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0\le a_i\le 10^9$$$).
The $$$s_i$$$ are encoded: in particular, let $$$k_i$$$ be the minimum number of colors needed on the prefix $$$s_1, s_2, \ldots, s_{i-1}$$$ with $$$k_1 = 0$$$. Then, $$$s_i := a_i \oplus k_i$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. It is guaranteed that $$$1\le s_i \le 2n$$$ and that all $$$s_i$$$ are distinct.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$7000$$$.
For each test case, on the first line, output $$$k$$$ — the minimum number of colors required for the full collection of piles.
On the $$$i$$$-th of the following $$$k$$$ lines, first print $$$\ell_i$$$ ($$$1 \leq \ell_i \leq n$$$) — the number of piles in the $$$i$$$-th color. Then print $$$\ell_i$$$ integers representing the sizes of the piles in the $$$i$$$-th color.
If there are multiple solutions, print any of them. We can show that an answer always exists for all prefixes.
331 3 261 3 2 6 7 10918 12 17 3 6 4 13 11 9
2 2 1 2 1 3 2 3 1 2 4 3 3 5 8 3 4 16 4 2 9 4 6 15 18 13 1 11
In the first example, we can recover the input as follows:
Thus, the piles have values $$$[1, 2, 3]$$$. We can show that the minimum number of colors required here is $$$2$$$, and a possible coloring is making the first and second pile color $$$1$$$, and the third pile color $$$2$$$.
| Name |
|---|


