311071: CF1930C. Lexicographically Largest

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Lexicographically Largesttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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:

  1. Select an index $i$ such that $1 \leq i \leq |a|$.
  2. Insert$^\dagger$ $a_i + i$ into $S$.
  3. Delete $a_i$ from $a$. Note that the indices of all elements to the right of $a_i$ 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 $b_i$ is the $i$-th largest element of $S$ for all $1 \leq i \leq |S|$.

Find the lexicographically largest$^\ddagger$ $b$ 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 $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 \ne 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]$.

Input

Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \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 $n$ ($1 \leq n \leq 3 \cdot 10^5$) — the length of array $a$.

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_{n}$ ($1 \leq a_i \leq 10^9$) — the elements of array $a$.

The sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.

Output

For each test case, output the lexicographically largest $b$.

ExampleInput
3
2
2 1
5
1 100 1000 1000000 1000000000
3
6 4 8
Output
3 2 
1000000005 1000004 1003 102 2 
11 7 6 
Note

In the first test case, select $i=1$ in the first operation, insert $a_1 + 1 = 3$ in $S$, and delete $a_1$ from $a$. After the first operation, $a$ becomes $a=[1]$. In the second operation, we select $i=1$ again and insert $a_1 + 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.

Output

题目大意:

Stack有一个长度为n的数组a。他还一个空集合S。注意S不是一个多重集。

他将准确地执行n次以下三个步骤的操作:

1. 选择一个索引i,使得1≤i≤|a|。
2. 插入†ai+i进入S。
3. 从a中删除ai。注意,ai右侧所有元素的索引将减少1。

注意,经过n次操作后,a将变为空。

Stack现在将构造一个新数组b,它是S按降序排序的。形式上,b是一个大小为|S|的数组,其中bi是S的第i大的元素,对于所有1≤i≤|S|。

找出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]。

输入输出数据格式:

输入:

每个测试包含多个测试用例。第一行包含一个整数t(1≤t≤10^4)——测试用例的数量。测试用例的描述如下。

每个测试用例的第一行包含一个整数n(1≤n≤3×10^5)——数组a的长度。

每个测试用例的第二行包含n个整数a1,a2,…,an(1≤ai≤10^9)——数组a的元素。

所有测试用例的n之和不超过3×10^5。

输出:

对于每个测试用例,输出字典序最大的b。题目大意: Stack有一个长度为n的数组a。他还一个空集合S。注意S不是一个多重集。 他将准确地执行n次以下三个步骤的操作: 1. 选择一个索引i,使得1≤i≤|a|。 2. 插入†ai+i进入S。 3. 从a中删除ai。注意,ai右侧所有元素的索引将减少1。 注意,经过n次操作后,a将变为空。 Stack现在将构造一个新数组b,它是S按降序排序的。形式上,b是一个大小为|S|的数组,其中bi是S的第i大的元素,对于所有1≤i≤|S|。 找出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]。 输入输出数据格式: 输入: 每个测试包含多个测试用例。第一行包含一个整数t(1≤t≤10^4)——测试用例的数量。测试用例的描述如下。 每个测试用例的第一行包含一个整数n(1≤n≤3×10^5)——数组a的长度。 每个测试用例的第二行包含n个整数a1,a2,…,an(1≤ai≤10^9)——数组a的元素。 所有测试用例的n之和不超过3×10^5。 输出: 对于每个测试用例,输出字典序最大的b。

加入题单

上一题 下一题 算法标签: