CJ蒟蒻一名,正在备战NOIP2019CSP2019。希望能进HNOI2019,THUWC。
考试和VJ题集的随笔的密码CJ的应该都知道。
如果哪里写锅了或者有什么需求可以直接评论。
至于个人记录嘛,能猜出来密码的随你看吧。
然后码风的话,比较压行和压大小,大括号换行。
就以静态区间第k小的主席树为例吧。
#include<bits/stdc++.h>
#define mid ((l+r)>>1)
using namespace std;
namespace IO
{
char ibuf[(1<<21)+1],obuf[(1<<21)+1],st[15],*iS,*iT,*oS=obuf,*oT=obuf+(1<<21);
char Get(){return (iS==iT? (iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT? EOF:*iS++)):*iS++);}
void Flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf;}
void Put(char x){*oS++=x;if(oS==oT)Flush();}
int read(){int x=0;char ch=Get();while(ch>57||ch<48)ch=Get();while(ch>=48&&ch<=57)x=x*10+(ch^48),ch=Get();return x;}
void write(int x){int top=0;if(!x)Put('0');while(x)st[++top]=(x%10)+48,x/=10;while(top)Put(st[top--]);Put('\n');}
}
using namespace IO;
const int N=100007;
int root[N],L[N<<5],R[N<<5],sum[N<<5],val[N<<5],a[N],t[N],n,m,cnt,tot,ST[11];
void insert(int &p,int pre,int x)
{
int l=1,r=tot,t; sum[t=p=++cnt]=sum[pre]+1;
while(l^r) (x<=mid)? (R[t]=R[pre],pre=L[pre],sum[t=L[t]=++cnt]=sum[pre]+1,r=mid):(L[t]=L[pre],pre=R[pre],sum[t=R[t]=++cnt]=sum[pre]+1,l=mid+1);
}
int query(int pre,int now,int k)
{
int l=1,r=tot,s;
for(;l^r;) ((s=sum[L[now]]-sum[L[pre]])>=k)? (r=mid,pre=L[pre],now=L[now]):(k-=s,l=mid+1,pre=R[pre],now=R[now]);
return t[l];
}
int main()
{
n=read(),m=read();int i,k,l,r;
for(i=1;i<=n;++i) a[i]=t[i]=read();
sort(t+1,t+n+1),tot=unique(t+1,t+n+1)-(t+1);
for(i=1;i<=n;++i) a[i]=lower_bound(t+1,t+tot+1,a[i])-t;
for(i=1;i<=n;++i) insert(root[i],root[i-1],a[i]);
while(m--) l=read(),r=read(),k=read(),write(query(root[l-1],root[r],k));
return Flush(),0;
}