传送门
就是说要维护一个数据结构资瓷区间反转和查询第\(K\)大,那么splay吧
我们可以把原数组按高度为第一关键字,下标为第二关键字排序,然后直接建出splay
这样的话每次第\(K\)大直接查询编号然后把它转到根节点,那么左子树大小+1就是下标了,区间反转打标记就好了
//minamoto
#include<bits/stdc++.h>
#define R register
#define inf 0x3f3f3f3f
#define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){R int res,f=1;R char ch;while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R int x){if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;while(z[++Z]=x%10+48,x/=10);while(sr[++C]=z[Z],--Z);sr[++C]=' ';
}
const int N=1e5+5;
struct node{int id,k;friend bool operator <(const node &a,const node &b){return a.k==b.k?a.id<b.id:a.k<b.k;}
}a[N];
int ch[N][2],fa[N],sz[N],tag[N],rt,n,ans,xx,yy;
inline int get(R int x){return ch[fa[x]][1]==x;}
inline void upd(R int x){sz[x]=sz[ch[x][0]]+sz[ch[x][1]]+1;}
void pd(R int x){if(tag[x]){if(ch[x][0])tag[ch[x][0]]^=1;if(ch[x][1])tag[ch[x][1]]^=1;swap(ch[x][0],ch[x][1]),tag[x]=0;}
}
void rotate(R int x){int y=fa[x],z=fa[y],d=get(x);pd(y),pd(x);ch[y][d]=ch[x][d^1],fa[ch[y][d]]=y,ch[x][d^1]=y,fa[y]=x,fa[x]=z;if(z)ch[z][ch[z][1]==y]=x;upd(y);
}
void splay(R int x,R int goal){for(R int y=fa[x],z=fa[y];y!=goal;y=fa[x],z=fa[y]){pd(z),pd(y),pd(x);if(z!=goal)rotate(get(x)==get(y)?y:x);rotate(x);}if(!goal)rt=x;
}
void build(R int l,R int r,R int fat){if(l>r)return;R int mid=(l+r)>>1;ch[fat][mid>fat]=mid,sz[mid]=1,fa[mid]=fat;if(l==r)return;build(l,mid-1,mid),build(mid+1,r,mid);upd(mid);
}
int Kth(int x){int now=rt;while(true){pd(now);if(ch[now][0]&&x<=sz[ch[now][0]])now=ch[now][0];else{x-=sz[ch[now][0]]+1;if(!x)return now;now=ch[now][1];}}
}
int main(){
// freopen("testdata.in","r",stdin);n=read();fp(i,2,n+1)a[i].k=read(),a[i].id=i;a[1].id=1,a[1].k=-inf,a[n+2].id=n+2,a[n+2].k=inf;sort(a+1,a+n+3),build(1,n+2,0),rt=(n+3)>>1;fp(i,2,n){splay(a[i].id,0),ans=sz[ch[rt][0]]+1;print(ans-1),xx=Kth(i-1),yy=Kth(ans+1);splay(xx,0),splay(yy,xx);tag[ch[ch[rt][1]][0]]^=1;}print(n);return Ot(),0;
}