[BZOJ1012]JSOI2008 最大数|线段树|平衡树
来源:互联网 发布:网络推广绩效考核方案 编辑:程序博客网 时间:2024/05/21 09:27
水题一道,显然线段树水过,不过我为了练练spaly就写了个splay作死,巨慢。。
#include<iostream>#include<cstdio>using namespace std;const int inf=99999999,maxn=200005;int m,d,i,nnode=0,root=0,last,l,get,c[maxn][2],size[maxn],lmax[maxn],num[maxn],pre[maxn];char cc;void update(int x){size[x]=size[c[x][1]]+size[c[x][0]]+1;lmax[x]=max(max(lmax[c[x][0]],lmax[c[x][1]]),num[x]);}void newnode(int &x,int fa,int k){x=++nnode;pre[x]=fa;num[x]=k;size[x]=1;lmax[x]=k;c[x][0]=c[x][1]=0;}void rot(int x,int kind){int y=pre[x];int z=pre[y];c[y][!kind]=c[x][kind];pre[c[x][kind]]=y;c[x][kind]=y;pre[y]=x;pre[x]=z;if (z) c[z][c[z][1]==y]=x;update(y);update(x);if (z) update(z);}void splay(int x,int goal){int y,z,kind;while (pre[x]!=goal){y=pre[x];if (pre[y]==goal) rot(x,c[y][0]==x);else{z=pre[y],kind=c[z][0]==y;if (c[y][kind]!=x) rot(y,kind); else rot(x,!kind);rot(x,kind);} }if (goal==0) root=x;}int findkth(int x,int k){if (k<=size[c[x][0]]) return findkth(c[x][0],k);if (k==size[c[x][0]]+1) return x;if (k>size[c[x][0]]+1) return findkth(c[x][1],k-1-size[c[x][0]]);}void insert(int k){get=root;while (c[get][1]) get=c[get][1];newnode(c[get][0],get,k);splay(c[get][0],0);}void solve(int l){get=findkth(root,nnode-l-1);splay(get,0);last=lmax[c[root][1]];printf("%d\n",last);}void print(int x){if (c[x][0]) print(c[x][0]);printf("x->num:%d,size:%d,pre:%d,lmax:%d\n",num[x],size[x],pre[x],lmax[x]);if (c[x][1]) print(c[x][1]);}int main(){scanf("%d%d",&m,&d);c[0][1]=c[0][0]=size[0]=pre[0]=0;num[0]=lmax[0]=-inf;last=0;newnode(root,0,-inf);newnode(c[root][1],root,-inf);update(root);for (i=1;i<=m;i++){scanf("%c",&cc);scanf("%c%d",&cc,&l);//print(root);if (cc=='A') insert((l+last)%d);else solve(l);}}
0 0
- [BZOJ1012]JSOI2008 最大数|线段树|平衡树
- 【bzoj1012】【JSOI2008】【最大数】【maxnumber】【线段树】
- [BZOJ1012][JSOI2008][线段树]最大数maxnumber
- 【线段树】BZOJ1012 [JSOI2008]最大数maxnumber
- bzoj1012 [JSOI2008] 最大数maxnumber 线段树
- [BZOJ1012][JSOI2008]最大数maxnumber(线段树)
- 线段树——BZOJ1012/Luogu1198 [JSOI2008]最大数
- BZOJ1012(JSOI2008)[最大数maxnumber]--线段树区间极值
- bzoj1012 [JSOI2008]最大数(单调栈+二分/线段树)
- bzoj1012: [JSOI2008]最大数maxnumber(线段树)
- jsoi2008最大数bzoj1012
- [BZOJ1012] [JSOI2008] 最大数
- 【BZOJ1012】【JSOI2008】最大数
- BZOJ1012 最大数maxnumber (线段树)
- 【JSOI2008】最大数 线段树
- [JSOI2008]最大数 --线段树
- [Bzoj1012][JSOI2008]最大数maxnumber
- bzoj1012[JSOI2008]最大数maxnumber
- eclipse 常用插件
- Vivado开发工具熟悉之Create custom IP
- PyQt学习笔记(16)——QTreeWidget
- 在MyEclipse中创建Java Maven依赖项目
- RMAN-08137: WARNING: archived log not deleted, needed for standby or upstream capture process
- [BZOJ1012]JSOI2008 最大数|线段树|平衡树
- 猫猫学IOS(二十一)UIApplication设置程序图标右上⾓红⾊数字_联⺴指⽰器等
- ios网络编程之Scoket
- 系统运行进程
- solr term 查询
- 高歌—【先声夺银】4.17 早间:金银反转未果,继续空
- Mac下安装git 及git在xcode中的简单使用
- nc UAP 调整最大内存
- RPG背包系统【1】