#P11066. 【MX-X4-T6】「Jason-1」电梯

【MX-X4-T6】「Jason-1」电梯

Background

Original link: https://oier.team/problems/X4G.

Problem Description

A building with nn floors has mm elevators. Each elevator can be in two states: stationary or moving.

Initially, elevator ii is stationary on floor ii. Given a permutation pp of 1m1 \sim m, you want elevator ii to end up on floor pip_i.

You can perform the following two types of operations:

  • 0: Move time forward by one moment.
  • x: where xx is a positive integer not exceeding nn.
    • To perform this operation, the following must hold: there is no stationary elevator on floor xx; the stationary elevator that is closest^\dagger to floor xx exists and is unique.
    • Let yy be the index of the nearest stationary elevator, and zz be its position. Then elevator yy immediately becomes a moving elevator, and it will arrive at floor xx and become stationary before all operations after xz\lvert x - z\rvert moments.

^\dagger: The distance between an elevator located on floor aa and floor xx is ax\lvert a - x\rvert.

Note: You must ensure that at any time, there are not two stationary elevators on the same floor.

For each testdata, there is a scoring parameter oo. You must construct a plan whose total number of operations does not exceed oo in order to pass that testdata.

This problem uses a custom checker to verify whether your answer is correct. Therefore, if there are multiple valid plans, you only need to output any one.

Input Format

This problem input contains multiple test cases.

The first line contains a positive integer TT, the number of test cases. For each test case:

  • The first line contains four positive integers Q,n,m,oQ, n, m, o, representing the number of queries, the number of floors, the number of elevators, and the scoring parameter.
  • The next QQ lines each contain mm integers p1,,pmp_1, \ldots, p_m, representing the target positions of the elevators.

Output Format

For each test case:

  • Output a total of 2Q2 Q lines. For each query, output two lines:
  • The first line contains a non-negative integer kk, the number of operations in your plan.
  • The second line contains kk integers in [0,n][0, n], representing your specific sequence of operations.

This problem uses a custom checker to verify whether your answer is correct. Therefore, if there are multiple valid plans, you only need to output any one.

2
2 4 2 12
1 2
2 1
1 10 5 30
5 4 3 2 1
0

9
3 4 0 0 1 0 2 0 0
16
6 6 6 6 6 0 1 0 2 0 3 0 4 0 5 0
1
1 6 5 30
5 4 3 2 1

16
6 6 6 6 6 0 1 0 2 0 3 0 4 0 5 0

Hint

[Sample Explanation #1]

This sample satisfies the constraints of Subtask 2.

For the first query of the first test case, no operation is needed.

For the second query of the first test case:

Operation Time Elevator 11 Position Elevator 22 Position
Initial state 00 11 22
33 moving
44 moving
00 11 33
22
11 moving
00 33 44
22 moving
00 44 11
55 22

[Sample Explanation #2]

This sample satisfies the constraints of Subtask 7.

[Constraints]

This problem uses bundled test.

Subtask nn \le m=m = o=o = Score
1 33 22 77
2 100100 n2\lfloor \frac{n}{2} \rfloor 2×(m+n)2\times(m+n) 1111
3 4040 n1n-1 3×n33 \times n^3 1717
4 200200 5×n25 \times n^2 1919
5 40004000 50×n50 \times n 1717
6 5×1045 \times 10^{4} 6×n6 \times n 1616
7 5×n5 \times n 1313

For all testdata, 1T201 \le T \le 20, 2m<n5×1042 \le m < n \le 5 \times 10^{4}. It is guaranteed that n,m,on, m, o simultaneously satisfy the constraints of some subtask above. pp is a permutation of 1m1 \sim m. 1Q2×1061 \le Q \le 2\times 10^6, oQ2×106\sum o Q \le 2 \times 10^6.

Translated by ChatGPT 5