#P12356. 「HCOI-R2」Rabbit Panic (Hard Ver.)

    ID: 11689 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>洛谷原创Special JudgeO2优化其它技巧构造洛谷月赛Ad-hoc

「HCOI-R2」Rabbit Panic (Hard Ver.)

Description

You have a sequence {pn}\{p_n\} where initially pi=i(1in)p_i = i(1 \leq i \leq n).

Each time you can choose mm distinct numbers i1,i2imi_1, i_2\dots i_m, and simultaneously set all of pi1,pi2pimp_{i_1}, p_{i_2}\dots p_{i_m} into their mean. Note that the mean may not be an integer. In this case, it will never be rounded.

You need to minimize the number of operations to make p1=p2==pnp_1 = p_2 = \dots = p_n.

Input Format

Each test consists of multiple test cases. The first line contains a single integer T(1T1.2×104)T(1\leq T\leq 1.2\times 10^4) --- the number of sets of test cases. The description of each test case follows.

In each test case, the only line contains two integers --- nn(1n2×1051 \leq n \leq 2\times 10^5) and mm(1mn1\le m\le n), representing the length of the sequence and the number mm.

It's guaranteed that the sum of nn over all testcases does not exceed 10610^6.

Output Format

For each test case, on the first line, output the minimum number of operations, ss.

On the next ss lines, each line contains mm distinct integers in the range [1,n][1, n] representing an operation.

If there's no solution, just print s=1s = -1.

If there are multiple solutions, print any.

1
6 4
2
1 2 5 6
2 3 4 5

Hint

Sample #1

  • $[1,2,3,4,5,6]\to [3.5,3.5,3,4,3.5,3.5]\to [3.5,3.5,3.5,3.5,3.5,3.5]$。
  • There may be different but valid solutions.

Constraints

This problem uses subtasks.

Note that the full score of this problem in this contest is 5050. Your actually score is half of the subtask scores displayed below.

  • Subtask 0 (20 pts): 1n101\leq \sum n\leq 10.
  • Subtask 1 (40 pts): 1n1031\leq \sum n\leq 10^3.
  • Subtask 2 (40 pts): No Special Constraints.

It is guaranteed that 1T1.2×1041 \leq T \leq 1.2\times 10^4, 1mn2×1051 \leq m \leq n \leq 2\times 10^5, 1n1061 \leq \sum n \leq 10^6.