Colored Blocks

시간 제한1초메모리 제한256 MB

요약
색깔이 칠해진 블록 열이 주어질 때, 같은 색이 연속하지 않도록 최소 개수의 부분수열(줄)로 나누고 그 배치를 출력한다.
난이도

보통10점 중 7점

유형
그리디, 시뮬레이션, 배열
정답자
아직 제출이 없습니다

문제

Busy Beaver is playing with his favorite blocks. There are NN blocks arranged in a row, each block having a color c_ic\_i. Busy Beaver hates seeing blocks of the same color next to each other, so he would like to rearrange the blocks into multiple rows, such that the blocks in each row are in the same ordering as they were in the original line, and no line has two consecutive blocks of the same color. Each of the NN original blocks should belong to exactly one of these rows.

Please help Busy Beaver determine an arrangement of blocks that uses the least possible number of lines.

입력

Each test contains multiple test cases. The first line of input contains a single integer TT (1≤T≤105)(1 \leq T \leq 10^5), the number of test cases. The description of each test case follows.

The first line of each test case contains a single positive integer NN (1≤N≤2⋅1051 \leq N \leq 2 \cdot 10^5) --- the number of blocks.

The second line contains NN space separated integers c_ic\_i (1≤c_i≤1091 \leq c\_i \leq 10^9) --- the color of the iith block.

It is guaranteed that the sum of NN across all test cases is no more than 2⋅1052 \cdot 10^5.

출력

For each test case, the first line of output should contain a single positive integer kk, the minimum number of rows that Busy Beaver needs to rearrange the blocks to satisfy his conditions.

For each of the next kk lines, output the number of blocks in that row, as well as the indices of the blocks themselves, space separated. Each of the rows must be nonempty.

If there are multiple solutions with the same minimum number of rows needed, output any one of them.

예제1

  1. 예제 1

    입력
    3
    2
    2 2
    3
    1 2 1
    4
    1 1 2 1
    
    예상 출력
    2
    1 1
    1 2
    1
    3 1 2 3
    2
    1 1
    3 2 3 4