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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
import java.io.*; import java.util.*; public class Main { static int[] a,f; static ST tr; static HashSet<Integer> st=new HashSet<Integer>(); static void print(int[] a,PrintWriter out){ int n=a.length-1; for(int i=1;i<=n;i++) out.print(a[i]+(i<n?" ":"")); out.println(); } public static void main(String[] args) throws IOException{ InputReader in=new InputReader(System.in); PrintWriter out=new PrintWriter(System.out); int T=in.nextInt(); while(T-->0){ int n=in.nextInt(); a=new int[n+1]; f=new int[n+1]; tr=new ST(n); tr.build(1, 1, n); for(int i=1;i<=n;i++) f[i]=in.nextInt(); for(int i=n;i>=1;i--){ f[i]-=f[i-1]; int tmp=tr.query(1, 1, n, f[i]+1);
a[i]=tmp; } print(a, out); } out.flush(); out.close(); } } class ST{ int[] l,r,m,v; int sz; ST(){} ST(int _sz){ sz=_sz<<2; l=new int[sz]; r=new int[sz]; m=new int[sz]; v=new int[sz]; } void build(int k,int x,int y){ l[k]=x;r[k]=y;m[k]=(x+y)>>1; if (x<y){ build(k<<1,x,m[k]); build(k<<1|1,m[k]+1,y); } v[k]=y-x+1; } int query(int k,int x,int y,int q){ if (l[k]==r[k]){ v[k]=0; return l[k]; } int res=0; if (v[k<<1|1]>=q) res=query(k<<1|1, m[k]+1, y, q); else res=query(k<<1,x,m[k],q-v[k<<1|1]); v[k]=v[k<<1]+v[k<<1|1]; return res; } }
|