CF1930C.Lexicographically Largest

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Stack has an array aa of length nn . He also has an empty set SS . Note that SS is not a multiset.

He will do the following three-step operation exactly nn times:

  1. Select an index ii such that 1ia1 \leq i \leq |a| .
  2. Insert ^\dagger ai+ia_i + i into SS .
  3. Delete aia_i from aa . Note that the indices of all elements to the right of aia_i will decrease by 11 .

Note that after nn operations, aa will be empty.

Stack will now construct a new array bb which is SS sorted in decreasing order. Formally, bb is an array of size S|S| where bib_i is the ii -th largest element of SS for all 1iS1 \leq i \leq |S| .

Find the lexicographically largest ^\ddagger bb that Stack can make.

^\dagger A set can only contain unique elements. Inserting an element that is already present in a set will not change the elements of the set.

^\ddagger An array pp is lexicographically larger than a sequence qq if and only if one of the following holds:

  • qq is a prefix of pp , but pqp \ne q ; or
  • in the first position where pp and qq differ, the array pp has a larger element than the corresponding element in qq .

Note that [3,1,4,1,5][3,1,4,1,5] is lexicographically larger than [3,1,3][3,1,3] , [][\,] , and [3,1,4,1][3,1,4,1] but not [3,1,4,1,5,9][3,1,4,1,5,9] , [3,1,4,1,5][3,1,4,1,5] , and [4][4] .

输入格式

Each test contains multiple test cases. The first line contains a single integer tt ( 1t1041 \leq t \leq 10^4 ) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn ( 1n31051 \leq n \leq 3 \cdot 10^5 ) — the length of array aa .

The second line of each test case contains nn integers a1,a2,,ana_1,a_2,\ldots,a_{n} ( 1ai1091 \leq a_i \leq 10^9 ) — the elements of array aa .

The sum of nn over all test cases does not exceed 31053 \cdot 10^5 .

输出格式

For each test case, output the lexicographically largest bb .

输入输出样例

  • 输入#1

    3
    2
    2 1
    5
    1 100 1000 1000000 1000000000
    3
    6 4 8

    输出#1

    3 2 
    1000000005 1000004 1003 102 2 
    11 7 6

说明/提示

In the first test case, select i=1i=1 in the first operation, insert a1+1=3a_1 + 1 = 3 in SS , and delete a1a_1 from aa . After the first operation, aa becomes a=[1]a=[1] . In the second operation, we select i=1i=1 again and insert a1+1=2a_1 + 1 = 2 in SS . Thus S={2,3}S=\{2, 3\} , and b=[3,2]b = [3, 2] .

Note that if you select i=2i=2 in the first operation, and i=1i=1 in the second operation, S={3}S=\{3\} as 33 will be inserted twice, resulting in b=[3]b=[3] .

As [3,2][3,2] is lexicographically larger than [3][3] , we should select i=1i=1 in the first operation.

In the second test case, in each operation, select the last element.

首页