The line tree is good.
Why one eye splay ah ...
Actually splay can also, but the line tree is more convenient?
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#defineMAXN 700500using namespacestd;intn,r,root,tot=0,ls[maxn<<2],rs[maxn<<2],val[maxn<<2],now;voidBuildint&now,intLeftintRight ) { Now=++tot;val[now]=right-left+1; if(Left==right)return; intMid= (left+right) >>1; Build (Ls[now],left,mid); Build (Rs[now],mid+1, right); return;}intQueryintNowintLeftintRightintx) {Val[now]--; if(Left==right)returnLeft ; intMid= (left+right) >>1; if(val[ls[now]]>=x)returnquery (LS[NOW],LEFT,MID,X); Else returnQuery (rs[now],mid+1, right,x-Val[ls[now]]);}intMain () {scanf ("%d",&N); Build (Root,1, N); for(intI=1; i<=n;i++) {scanf ("%d",&R); now= (now+r)% (n-i+1); printf ("%d\n", Query (Root,1, n,now+1)); } return 0;}
Bzoj 4415 Licensing