ZYB ' s premutation Memory limit:131072/131072 K (java/others)Problem description
ZYBZYb There is an arrangementPP, but he only remembersPThe inverse logarithm of each prefix interval in P, and now he asks you to restore the arrangement.(I,J) (I < J)(I,J)(I<J) is called a pair of inverse pairs when and only ifa_i>a_jA? I?? >A? J??
Enter a description
First line an integerTT represents the number of data groups. Next each set of data: First line a positive integerNN, which describes the length of the arrangement. Second lineNn a positive integerA_iA?I??, describe the prefix interval[1,i][1,i 1 \leq T \leq 51≤t≤5,1 \leq N \ Leq 50000 1≤N< Span class= "Mrel" >≤5000 0
Output description
the T-line rows of n-n integers represent the arrangement of answers.
Input sample
130 1 2
Output sample
3 1 2
Solving: SetF_iF?I?? is the firstIThe inverse logarithm of the i prefix,P_iP?I?? is the firstIThe number on the I position, thenF_I-F_{I-1}F?I??−F?I−1?? IsII front ratioP_iP?I?? The number of large numbers. We're thinking of doing it backwards when we're done withII after the number, the firstIThe number of I is the remainder of the firstF_i-f_{i-1}+1F?I??−F?I−1?? +1 large number, with line segment tree and tree array can easily find the current K k a 11 location, complexity of Span class= "Katex" >o (n \log N) o (nlogn).
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intMAXN = 5e4 + -;Long LongARR[MAXN],B[MAXN];#defineLowbit (x) ((x) & (-X))structbinaryindextree{intVal[maxn],sz; voidInitintSZ) { This->sz=sz; Memset (Val,0,sizeof(int) * (sz+5)); } voidUpdata (intPosintkey) { while(pos<=SZ) {Val[pos]+=key; POS+=Lowbit (POS); } } intPrefixsum (intPOS) { intres=0; while(pos>0) {res+=Val[pos]; POS-=Lowbit (POS); } returnRes; } intQueryintLintR) { returnPrefixsum (R)-prefixsum (l1); } //find the first position greater than or equal to K returns//if not present, return-1 intLower_bound (intk) { if(Prefixsum (SZ) <k)return-1; intL =1, r =sz; while(L <=R) { intMID = L + ((r-l) >>1); if(Prefixsum (mid) < K) L = mid +1; ElseR = Mid-1; } returnl; }}solver;intANS[MAXN];intMainintargcChar*argv[]) { intCase ; scanf ("%d",&Case ); while(case--){ intN; scanf ("%d",&N); Solver.init (n); for(inti =1; I <= N; + + i) scanf ("%i64d", arr+i); for(inti =1; I <= N; + + i) b[i] = arr[i]-arr[i-1]; for(inti =1; I <= N; + + i) solver.updata (i,1); for(inti = n; I >=1; --i) { Long LongRank = i-B[i]; intt =Solver.lower_bound (rank); Ans[i]=T; Solver.updata (T,-1); } printf ("%d", ans[1]); for(inti =2; I <= N; + + i) printf ("%d", Ans[i]); printf ("\ n"); } return 0;}
Code
Hdu5592/bestcoder Round #65 tree-like array looking for the K-large