CF1930C.Lexicographically Largest

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

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 1≤i≤∣a∣1 \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 1≤i≤∣S∣1 \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 p≠qp \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].

Stack 有一个长度为 nn 的数组 aa,以及一个空集合 SS。注意:SS 不是多重集(即不包含重复元素)。

他将恰好执行 nn 次如下三步操作:

  1. 选择一个下标 ii,满足 1≤i≤∣a∣1 \leq i \leq |a|;
  2. 将 ai+ia_i + i 插入†^\dagger 到集合 SS 中;
  3. 从数组 aa 中删除 aia_i;注意:aia_i 右侧所有元素的下标均减 11。

注意:经过 nn 次操作后,aa 将为空。

随后,Stack 将构造一个新数组 bb,其为集合 SS 中所有元素按降序排列所得。形式化地,bb 是一个长度为 ∣S∣|S| 的数组,对所有 1≤i≤∣S∣1 \leq i \leq |S|,bib_i 表示 SS 中第 ii 大的元素。

请找出 Stack 能构造出的字典序最大‡^\ddagger 的数组 bb。

†^\dagger 集合仅能包含互异元素。若向集合中插入一个已存在的元素,则集合内容不变。

‡^\ddagger 数组 pp 字典序大于序列 qq,当且仅当满足以下任一条件:

  • qq 是 pp 的前缀,但 p≠qp \ne q;或
  • 在 pp 与 qq 首次出现差异的位置上,pp 中对应位置的元素严格大于 qq 中对应位置的元素。

注意:[3,1,4,1,5][3,1,4,1,5] 字典序大于 [3,1,3][3,1,3]、[ ][\,] 和 [3,1,4,1][3,1,4,1],但不大于 [3,1,4,1,5,9][3,1,4,1,5,9]、[3,1,4,1,5][3,1,4,1,5] 和 [4][4]。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1041 \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 (1≤n≤3⋅1051 \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} (1≤ai≤1091 \leq a_i \leq 10^9) — the elements of array aa.

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

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

每个测试用例的第一行包含一个整数 nn(1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^5),表示数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_{n}(1≤ai≤1091 \leq a_i \leq 10^9),表示数组 aa 的元素。

所有测试用例中 nn 的总和不超过 3⋅1053 \cdot 10^5。

输出格式

For each test case, output the lexicographically largest bb.

对于每个测试用例,输出字典序最大的 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,3S={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=3S={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.

在第一个测试用例中,第一次操作选择 i=1i=1,将 a1+1=3a_1 + 1 = 3 插入集合 SS,并从数组 aa 中删除 a1a_1。第一次操作后,aa 变为 a=[1]a=[1]。第二次操作中,再次选择 i=1i=1,并将 a1+1=2a_1 + 1 = 2 插入 SS。因此 S={2,3}S=\{2, 3\},且 b=[3,2]b = [3, 2]。

注意:若第一次操作选择 i=2i=2,第二次操作选择 i=1i=1,则 33 将被插入两次,导致 S={3}S=\{3\},从而 b=[3]b=[3]。

由于 [3,2][3,2] 的字典序大于 [3][3],我们应在第一次操作中选择 i=1i=1。

在第二个测试用例中,每次操作均选择最后一个元素。

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

首页