Miss_you @ 2022-08-07 10:59:11
#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long
#define midd() int mid=(l+r)>>1
using namespace std;
const int N(1e5+1);
struct Node{
int ls,rs,val;
}tre[N<<2];
vector<int> v;
int a[N],cnt,rt,n;
bool vis[N];
inline int getid(int x){
return lower_bound(v.begin(),v.end(),x)-v.begin()+1;
}
void ins(int l,int r,int &nw,int val)
{
if(!vis[val])vis[val]=true,nw=++cnt;
tre[nw].val++;
if(l==r)return ;
midd();
if(val<=mid)return ins(l,mid,tre[nw].ls,val);
return ins(mid+1,r,tre[nw].rs,val);
}
int query(int l,int r,int nw,int p)
{
if(l==r)return l;
midd();
if(p<=tre[tre[nw].ls].val)return query(l,mid,tre[nw].ls,p);
return query(mid+1,r,tre[nw].rs,p-tre[tre[nw].ls].val);
}
int main()
{
register int i;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",a+i),v.push_back(a[i]);
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
printf("%d\n",a[1]);
ins(1,n,rt,getid(a[1]));
for(i=1;i*2<n;i++)
ins(1,n,rt,getid(a[i*2])),ins(1,n,rt,getid(a[i*2+1])),printf("%d\n",query(1,n,rt,i+1));
return 0;
}
个人第一次打权值线段树。。。算是乱打的吧