-
Notifications
You must be signed in to change notification settings - Fork 0
/
ORDERS.java
48 lines (46 loc) · 1005 Bytes
/
ORDERS.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package ques;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
public class ORDERS {
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t>0){
t--;
int n=Integer.parseInt(br.readLine());
String[] s=br.readLine().split(" ");
int[] arr=new int[n];
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(s[i]);
}
int[] ar=new int[n];
for(int i=0;i<n;i++){
ar[i]=i+1;
}
for(int i=0;i<n;i++){
ar[i]=ar[i]-arr[i];
}
int count=0;
int x=ar[n-1];
HashSet<Integer> hs=new HashSet<Integer>();
for(int i=n-2;i>=0;i--){
if(ar[i]==x){
count++;
while(hs.contains(ar[i]+count))
count++;
ar[i]+=count;
hs.add(ar[i]);
}
else{
x=ar[i];
count=0;
}
}
for(int i=0;i<n;i++){
System.out.print(ar[i]+" ");
}
System.out.println();
}
}
}