luogu#P16326. 星降る海

    ID: 16210 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>模拟贪心洛谷原创Special JudgeO2优化构造洛谷月赛分类讨论

星降る海

Problem Description

You are given a color sequence aa of length nn and a positive integer kk. You may perform the following operation any number of times.

  • Choose a subset SS of {1,2,,n}\{1,2,\ldots,n\} and a color cc, then change the color of every position in SS to cc.

Determine the minimum number of operations needed to make the number of maximal color segments exactly kk, and construct a solution.

If there are multiple possible constructions, you may output any.

Input Format

The first line contains two positive integers n,kn,k.

The second line contains nn positive integers aia_i, denoting the color sequence.

Output Format

Print the minimum number of operations tt on the first line.

Then print tt lines describing the operations in order. For each line, the first integer sis_i denotes the size of the chosen set, followed by sis_i distinct integers between 11 and nn indicating the elements of the set, and finally an integer cc between 11 and nn denoting the new color.

5 3
1 2 3 3 3
0
5 2
1 2 3 3 3
1
1 2 1
5 4
1 2 3 3 3
1
2 4 5 4

Hint

Constraints

For all test cases, 1kn1051\le k\le n\le 10^5 and 1ain1\le a_i\le n.

Subtask nn\le Special Property Score
11 66 None 2020
22 10510^5 A
33 B
44 None 4040
  • Special Property A: It is guaranteed that k=1k=1.
  • Special Property B: It is guaranteed that k=nk=n.