CF1930C.Lexicographically Largest
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
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].
Stack 有一个长度为 n 的数组 a,以及一个空集合 S。注意:S 不是多重集(即不包含重复元素)。
他将恰好执行 n 次如下三步操作:
- 选择一个下标 i,满足 1≤i≤∣a∣;
- 将 ai+i 插入† 到集合 S 中;
- 从数组 a 中删除 ai;注意:ai 右侧所有元素的下标均减 1。
注意:经过 n 次操作后,a 将为空。
随后,Stack 将构造一个新数组 b,其为集合 S 中所有元素按降序排列所得。形式化地,b 是一个长度为 ∣S∣ 的数组,对所有 1≤i≤∣S∣,bi 表示 S 中第 i 大的元素。
请找出 Stack 能构造出的字典序最大‡ 的数组 b。
† 集合仅能包含互异元素。若向集合中插入一个已存在的元素,则集合内容不变。
‡ 数组 p 字典序大于序列 q,当且仅当满足以下任一条件:
- q 是 p 的前缀,但 p=q;或
- 在 p 与 q 首次出现差异的位置上,p 中对应位置的元素严格大于 q 中对应位置的元素。
注意:[3,1,4,1,5] 字典序大于 [3,1,3]、[] 和 [3,1,4,1],但不大于 [3,1,4,1,5,9]、[3,1,4,1,5] 和 [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.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤3⋅105),表示数组 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109),表示数组 a 的元素。
所有测试用例中 n 的总和不超过 3⋅105。
输出格式
For each test case, output the lexicographically largest b.
对于每个测试用例,输出字典序最大的 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.
在第一个测试用例中,第一次操作选择 i=1,将 a1+1=3 插入集合 S,并从数组 a 中删除 a1。第一次操作后,a 变为 a=[1]。第二次操作中,再次选择 i=1,并将 a1+1=2 插入 S。因此 S={2,3},且 b=[3,2]。
注意:若第一次操作选择 i=2,第二次操作选择 i=1,则 3 将被插入两次,导致 S={3},从而 b=[3]。
由于 [3,2] 的字典序大于 [3],我们应在第一次操作中选择 i=1。
在第二个测试用例中,每次操作均选择最后一个元素。
输入解题思路,AI测评打分。不知道怎么写?