Test instructions: I'll give you the N plate. Follow (1....N) from top to down, then M ask, each time take out x disc, output x above the number of discs and put this disc to the beginning
Directly think is actually a segment of the interval update, single-point evaluation, but according to test instructions we can think of
First we save the n--1, then we put the plates at the end each time we ask, so we're going to open a map array to map where each plate is.
Where we need to use a tree array to maintain each absolute position if there is a plate (some of the dishes have been placed behind), and then use the interval sum.
#include <Set>#include<map>#include<queue>#include<stack>#include<cmath>#include<vector>#include<string>#include<cstdio>#include<cstring>#include<stdlib.h>#include<iostream>#include<algorithm>using namespacestd;#defineEPS 1E-8/*Note that there may be output -0.000*/#defineSGN (x) (X<-eps -1:x<eps? 0:1)//X is a comparison of two floating-point numbers, note the return integer#defineCvs (x) (x > 0.0 x+eps:x-eps)//floating point Conversion#defineZero (x) (((x) >0? ( x):-(x)) <eps)//determine if it equals 0#defineMul (A, B) (a<<b)#defineDir (A, B) (a>>b)typedefLong Longll;typedef unsignedLong Longull;Const intinf=1<< -;Const DoublePi=acos (-1.0);Const intmod=1e9+7;Const intmax=200010;//twice times, because to add backwardsintMp[max],bit[max],tot,tol;//Map location Mapped tree array total sizeintLowbit (intx) { returnx& (-x);}voidADD (intXinty) { while(x<=tol) {Bit[x]+=y; X+=lowbit (x); } return ;}intSum (intx) { intsum=0; while(x) {sum+=Bit[x]; X-=lowbit (x); } returnsum;}voidInit (intNintm) {memset (bit,0,sizeof(bit)); Tot=N; Tol=n+m; for(intI=1; i<=n; ++i)//Reverse Storage{Mp[i]=n-i+1; ADD (Mp[i],1); } return;}intSolve (intNintm) {ll ans=0; intpos=Mp[m]; //printf ("\npos=%d\n", POS);Ans=n-sum (POS);//ask for the backtot++; ADD (POS,-1);//UpdateADD (Tot,1); MP[M]=tot;//map to start returnans;}intMain () {intT,n,m,num; scanf ("%d",&t); while(t--) {scanf ("%d%d",&n,&m); Init (N,M); for(intI=0; i<m;++i) {scanf ("%d",&num); printf ("%d%c", Solve (n,num), i==m-1?'\ n':' '); } } return 0;}
UVA 1513 Movie Collection (tree-like array + reverse storage)