Title Summary: There is a full permutation, always the inverse logarithm of each prefix interval, to restore this arrangement.
Fi Records in reverse order logarithm, PI records the position value, then k=fi-f (i-1) indicates the number of previous i-1 is larger than PI, then as long as the remaining elements in order to find the number of i-k numbers can be.
Segment tree + binary search, Segment tree bit[i] records the rank order of the remaining elements in I.
1 /*******************************2 3 date:2015-12-06 19:49:594 AUTHOR:WQJ ([email protected])5 Link:http://www.cnblogs.com/a1225234/6 Name:7 8 ********************************/9#include <iostream>Ten#include <cstdio> One#include <algorithm> A#include <cmath> -#include <cstring> -#include <string> the#include <Set> -#include <vector> -#include <queue> -#include <stack> + #defineLL Long Long - using namespacestd; + inta[ the+Ten]; A intbit[ the+Ten]; at intans[ the+Ten]; - intN; - intLowbit (inti) - { - returni&-i; - } in intSuminti) - { to ints=0; + while(i>0) - { thes+=Bit[i]; *i-=lowbit (i); $ }Panax Notoginseng returns; - } the voidAddintIinta) + { A while(i<=N) the { +bit[i]+=A; -i+=lowbit (i); $ } $ } - intMain () - { theFreopen ("In.txt","R", stdin); - inti,j;Wuyi intT; thescanf"%d",&T); - while(t--) Wu { -scanf"%d",&n); About for(i=1; i<=n;i++) scanf ("%d",&A[i]); $a[0]=0; -memset (bit,0,sizeof(bit)); - for(i=1; i<=n;i++) Add (i,1);/*record the size of I in a tree-like array*/ - for(i=n;i>=1; i--) A { + inttemp=a[i]-a[i-1]; theTemp=i-temp;//number of temp in the first row - intL=1, r=N,mid; $ intk=R; the while(r>=l) the { theMid= (r+l)/2; the if(Sum (mid) >=temp) {k=mid;r=mid-1;} - ElseL=mid+1; in } theans[i]=K; theAdd (ans[i],-1); About } the for(i=1; i<=n;i++) theprintf"%d%c", Ans[i],i==n?'\ n':' '); the } + return 0; -}
BC ZYB ' s premutation (segment tree + binary search)