BZOJ 2223: [Coci 2009]PATULJCI 主席树
来源:互联网 发布:java获取当天0点时间 编辑:程序博客网 时间:2024/06/05 03:14
2223: [Coci 2009]PATULJCI
Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1171 Solved: 497
[Submit][Status][Discuss]
Description
Input
Output
10 3 1 2 1 2 1 2 3 2 3 3 8 1 2 1 3 1 4 1 5 2 5 2 6 6 9 7 10
Sample Input
no
yes 1
no
yes 1
no
yes 2
no
yes 3
yes 1
no
yes 1
no
yes 2
no
yes 3
Sample Output
HINT
Notice:输入第二个整数是序列中权值的范围Lim,即1<=ai(1<=i<=n)<=Lim。
1<=Lim<=10000
好久没写主席树,都快忘了。。。
水一道 题解见传送门
#include<cmath>#include<ctime>#include<cstdio>#include<cstdlib>#include<cstring>#include<complex>#include<iostream>#include<algorithm>#include<iomanip>#include<vector>#include<string>#include<queue>#include<set>#include<map>using namespace std;inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return f*x;}const int N=301000;int n,lim,m,cnt,root[N];struct president_tree{int ls,rs,w;}tr[N<<4];void add(int l,int r,int x,int &y,int val){y=++cnt;tr[y].w=tr[x].w+1;int mid=l+r>>1;if(l==r)return ;tr[y].ls=tr[x].ls;tr[y].rs=tr[x].rs;if(mid>=val)add(l,mid,tr[x].ls,tr[y].ls,val);else if(mid<val)add(mid+1,r,tr[x].rs,tr[y].rs,val);}void query(int a,int b){int x=root[a-1],y=root[b],l=1,r=lim,aim=(b-a+1)>>1;while(l!=r){int mid=l+r>>1;if(tr[y].w-tr[x].w<=aim){puts("no");return ;}if(tr[tr[y].ls].w-tr[tr[x].ls].w>aim){x=tr[x].ls;y=tr[y].ls;r=mid;}else if(tr[tr[y].rs].w-tr[tr[x].rs].w>aim){x=tr[x].rs;y=tr[y].rs;l=mid+1;}else {puts("no");return ;}}printf("yes %d\n",l);}int main(){n=read();lim=read();int x,y;for(int i=1;i<=n;i++){add(1,lim,root[i-1],root[i],read());}m=read();while(m--){x=read();y=read();query(x,y);}return 0;}/*10 3 1 2 1 2 1 2 3 2 3 3 8 1 2 1 3 1 4 1 5 2 5 2 6 6 9 7 10*/
阅读全文
0 0
- 【BZOJ 2223】 [Coci 2009]PATULJCI 主席树
- BZOJ 2223: [Coci 2009]PATULJCI 主席树
- BZOJ 2223 [Coci 2009]PATULJCI 主席树
- [主席树] BZOJ 3524 [Poi2014]Couriers BZOJ 2223 [Coci 2009]PATULJCI
- 【BZOJ】3524 [Poi2014]Couriers && 【BZOJ】2223 [Coci 2009]PATULJCI 主席树
- bzoj 2223: [Coci 2009]PATULJCI
- BZOJ 2223: [Coci 2009]PATULJCI
- BZOJ 2223: [Coci 2009]PATULJCI
- 3524: [Poi2014]Couriers/2223: [Coci 2009]PATULJCI 主席树
- 【bzoj3524/2223】[Poi2014]Couriers/[Coci 2009]PATULJCI 主席树
- bzoj2223: [Coci 2009]PATULJCI 主席树
- [bzoj2223][Coci 2009]PATULJCI 主席树
- bzoj 2223: [Coci 2009]PATULJCI 可持久化线段树
- [分块 随机化] BZOJ 2223 [Coci 2009]PATULJCI
- [BZOJ2223][[Coci 2009]PATULJCI][主席树+特判]
- 3524: [Poi2014]Couriers/2223: [Coci 2009]PATULJCI
- bzoj3524: [Poi2014]Couriers&&2223: [Coci 2009]PATULJCI
- [BZOJ2223][Coci 2009]PATULJCI
- 学习笔记2之继承
- hibernate原理和优点
- 使用本地广播
- 阿里云服务器配置可访问端口
- do{}while()和 while(){}的区别
- BZOJ 2223: [Coci 2009]PATULJCI 主席树
- ambari数据库分析-adminresource
- node.js学习笔记
- 多进程 VS 多线程
- Telnet命令检测远程主机上的端口是否开启
- ES6-Class 记录
- C Primer Plus 第9章 函数 编程练习
- OTT-TV网络电视EPG录制和EPG抓取解决方案
- 历届试题 打印十字图