|
||||||||||
BellovinTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2841 Accepted Submission(s): 1086 Problem Description Peter has a sequence $a_1,a_2,...,a_n$ and he define a function on the sequence -- $F(a_1,a_2,...,a_n)=(f_1,f_2,...,f_n)$, where $f_i$ is the length of the longest increasing subsequence ending with $a_i$. Peter would like to find another sequence $b_1,b_2,...,b_n$ in such a manner that $F(a_1,a_2,...,a_n)$ equals to $F(b_1,b_2,...,b_n)$. Among all the possible sequences consisting of only positive integers, Peter wants the lexicographically smallest one. The sequence $a_1, a_2, ..., a_n$ is lexicographically smaller than sequence $b_1, b_2, ..., b_n$, if there is such number $i$ from $1$ to $n$, that $a_k = b_k$ for $1 \le k < i$ and $a_i < b_i$. Input There are multiple test cases. The first line of input contains an integer $T$, indicating the number of test cases. For each test case: The first contains an integer $n$ $(1 \le n \le 100000)$ -- the length of the sequence. The second line contains $n$ integers $a_1,a_2,...,a_n$ $(1 \le a_i \le 10^9)$. Output For each test case, output $n$ integers $b_1,b_2,...,b_n$ $(1 \le b_i \le 10^9)$ denoting the lexicographically smallest sequence. Sample Input
Sample Output
Source | ||||||||||
|