CF1930C.Lexicographically Largest
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Stack has an array a of length n . He also has an empty set S . Note that S is not a multiset.
He will do the following three-step operation exactly n times:
- Select an index i such that 1≤i≤∣a∣ .
- Insert † ai+i into S .
- Delete ai from a . Note that the indices of all elements to the right of ai will decrease by 1 .
Note that after n operations, a will be empty.
Stack will now construct a new array b which is S sorted in decreasing order. Formally, b is an array of size ∣S∣ where bi is the i -th largest element of S for all 1≤i≤∣S∣ .
Find the lexicographically largest ‡ b that Stack can make.
† 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.
‡ An array p is lexicographically larger than a sequence q if and only if one of the following holds:
- q is a prefix of p , but p=q ; or
- in the first position where p and q differ, the array p has a larger element than the corresponding element in q .
Note that [3,1,4,1,5] is lexicographically larger than [3,1,3] , [] , and [3,1,4,1] but not [3,1,4,1,5,9] , [3,1,4,1,5] , and [4] .
输入格式
Each test contains multiple test cases. The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n ( 1≤n≤3⋅105 ) — the length of array a .
The second line of each test case contains n integers a1,a2,…,an ( 1≤ai≤109 ) — the elements of array a .
The sum of n over all test cases does not exceed 3⋅105 .
输出格式
For each test case, output the lexicographically largest b .
输入输出样例
输入#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=1 in the first operation, insert a1+1=3 in S , and delete a1 from a . After the first operation, a becomes a=[1] . In the second operation, we select i=1 again and insert a1+1=2 in S . Thus S={2,3} , and b=[3,2] .
Note that if you select i=2 in the first operation, and i=1 in the second operation, S={3} as 3 will be inserted twice, resulting in b=[3] .
As [3,2] is lexicographically larger than [3] , we should select i=1 in the first operation.
In the second test case, in each operation, select the last element.