CF1746C.Permutation Operations

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a permutation aa of size nn and you should perform nn operations on it. In the ii-th operation, you can choose a non-empty suffix of aa and increase all of its elements by ii. How can we perform the operations to minimize the number of inversions in the final array?

Note that you can perform operations on the same suffix any number of times you want.

A permutation of size nn is an array of size nn such that each integer from 11 to nn occurs exactly once in this array. A suffix is several consecutive elements of an array that include the last element of the array. An inversion in an array aa is a pair of indices (i,j)(i, j) such that i>ji \gt j and ai<aja_{i} \lt a_{j}.

给你一个长度为 nn 的排列 aa,你需要对其执行 nn 次操作。在第 ii 次操作中,你可以选择 aa 的一个非空后缀,并将该后缀中所有元素增加 ii。如何执行这些操作,使得最终数组中的逆序对数量最少?

注意:你可以任意多次对同一后缀执行操作。

长度为 nn 的排列是指一个长度为 nn 的数组,其中恰好包含从 11 到 nn 的每个整数各一次。后缀是指包含数组最后一个元素的若干连续元素组成的子数组。数组 aa 中的一个逆序对是指一对下标 (i,j)(i, j),满足 i>ji \gt j 且 ai<aja_{i} \lt a_{j}。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1051 \le n \le 10^5) — the size of the array.

The second line contains nn distinct integers a1,a2,…,ana_{1}, a_{2}, \dots, a_{n} (1≤ai≤n1 \le a_i \le n), the initial permutation aa.

It's guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)—— 数组的大小。

第二行包含 nn 个互不相同的整数 a1,a2,…,ana_{1}, a_{2}, \dots, a_{n}(1≤ai≤n1 \le a_i \le n),即初始排列 aa。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print nn integers x1,x2,…,xnx_{1}, x_{2}, \ldots, x_{n} (1≤xi≤n1 \le x_{i} \le n for each 1≤i≤n1 \le i \le n) indicating that the ii-th operation must be applied to the suffix starting at index xix_{i}. If there are multiple answers, print any of them.

对于每个测试用例,输出 nn 个整数 x1,x2,…,xnx_{1}, x_{2}, \ldots, x_{n}(对每个 1≤i≤n1 \le i \le n,满足 1≤xi≤n1 \le x_{i} \le n),表示第 ii 个操作必须应用于从索引 xix_{i} 开始的后缀。若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

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

    输出#1

    1 1 1 1
    1 4 3 2 1
    1 3 3
    1

说明/提示

In the first test case one of the optimal solutions is to increase the whole array on each operation (that is, choose the suffix starting at index 11). The final array [11,12,13,14][11, 12, 13, 14] contains 00 inversions.

In the second test case, aa will be equal to [2,4,3,5,6][2, 4, 3, 5, 6], [2,4,3,7,8][2, 4, 3, 7, 8], [2,4,6,10,11][2, 4, 6, 10, 11], [2,8,10,14,15][2, 8, 10, 14, 15] and [7,13,15,19,20][7, 13, 15, 19, 20] after the first, second, third, fourth, and fifth operations, respectively. So the final array aa has zero inversions.

在第一个测试用例中,一种最优解是在每次操作中对整个数组进行增加(即选择从下标 11 开始的后缀)。最终数组 [11,12,13,14][11, 12, 13, 14] 包含 00 个逆序对。

在第二个测试用例中,经过第一次、第二次、第三次、第四次和第五次操作后,数组 aa 将分别变为 [2,4,3,5,6][2, 4, 3, 5, 6]、[2,4,3,7,8][2, 4, 3, 7, 8]、[2,4,6,10,11][2, 4, 6, 10, 11]、[2,8,10,14,15][2, 8, 10, 14, 15] 和 [7,13,15,19,20][7, 13, 15, 19, 20]。因此,最终数组 aa 的逆序对数量为 00。

输入解题思路,AI测评打分。不知道怎么写?

首页