#P16534. [THUPC 2026 决赛] 年鉴整理

[THUPC 2026 决赛] 年鉴整理

Background

From the finals of the 2026 Tsinghua University Student Programming Contest and Collegiate Invitational (THUPC2026).

Resources such as editorials can be found at https://github.com/dapingguo8/THUPC2026-final.

The tea party was nearing its end. As a special nostalgic event for the 10th anniversary celebration, Little T deliberately brought out the precious archives of past THUPC contests—a row of contest yearbooks recording bits and pieces of the past ten years—for everyone to read.

After reading, the two of them were going to put the yearbooks back on the shelf. As time had passed, the degree of damage of the yearbooks varied. Careful Little S suggested that, when putting them back, they should be reordered in strictly increasing order of damage, so that the traces of time could be shown more clearly. However, the paper of the yearbooks was already very fragile: each time, they could only move one yearbook forward by one position extremely carefully, and this would inevitably slightly increase the damage of that yearbook. What was worse, the time left for sorting was very limited. Little S wanted to know whether it was possible, within a limited number of operations, to put these yearbooks back on the shelf and make them neatly ordered.

Problem Description

There are nn yearbooks on the shelf. Initially, the damage of the ii-th (1≤i≤n1 \le i \le n) yearbook is aia_i.

In each move, you must first choose a position pp (1≤p≤n−11 \le p \le n - 1), then move the (p+1)(p + 1)-th yearbook forward to be in front of the pp-th yearbook. After the move, its damage will increase by 11.

Due to limited time, you can make at most n2−nn ^ 2 - n moves in total. As one of the many participants who read the yearbooks, you need to help Little S plan a specific sequence of moves so that, in the end, the damages of the yearbooks on the shelf are strictly increasing from left to right.

Input Format

Each test contains multiple sets of testdata. The first line contains a positive integer TT (1≤T≤101 \le T \le 10), which is the number of test cases. For each test case:

  • The first line contains a positive integer nn (1≤n≤5001 \le n \le 500), the number of yearbooks.
  • The second line contains nn positive integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9), representing the initial damage of each yearbook.

Output Format

For each test case, if there exists a feasible sequence of moves:

  • Output a non-negative integer kk (0≤k≤n2−n0 \le k \le n ^ 2 - n) in the first line, representing the number of moves.
  • Output kk positive integers p1,p2,…,pkp_1, p_2, \dots, p_k (1≤pi≤n−11 \le p_i \le n - 1) in the second line, representing the chosen position in each move.

If it is impossible to make the final damages strictly increasing from left to right, output only one line containing an integer −1-1.

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

-1
2
2 1 

Hint

  • For the first test case, the sequence [1,2][1,2] is already strictly increasing.
  • For the second test case, it is impossible to turn the sequence [2,1][2,1] into a strictly increasing sequence within the allowed number of steps.
  • For the third test case, first choose index 22 to change the sequence to [4,2,5][4,2,5]; then choose index 11 to change the sequence to [3,4,5][3,4,5].

Translated by ChatGPT 5