博客公告

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;
}

转载于:https://www.cnblogs.com/cjoierShiina-Mashiro/p/11492447.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值