BZOJ 1251 Splay维护序列
来源:互联网 发布:无间道为什么经典 知乎 编辑:程序博客网 时间:2024/05/17 23:04
思路:
splay维护序列的裸题
啊woc调了一天
感谢yzy大佬的模板……
//By SiriusRen#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define N 55555#define inf 0x3f3f3f3fint n,m,root,cnt,size[N],ch[N][2],fa[N],v[N],mx[N],rev[N],tag[N];int build(int l,int r){ if(l>r)return 0; if(l==r){size[l]=1;return l;} int mid=(l+r)>>1; ch[mid][0]=build(l,mid-1);fa[ch[mid][0]]=mid; ch[mid][1]=build(mid+1,r);fa[ch[mid][1]]=mid; size[mid]=size[ch[mid][0]]+size[ch[mid][1]]+1; return mid;}void push_up(int x){ mx[0]=-inf; size[x]=size[ch[x][0]]+size[ch[x][1]]+1; mx[x]=max(mx[ch[x][0]],max(mx[ch[x][1]],v[x]));}void push_down(int x){ if(rev[x]){rev[ch[x][0]]^=1,rev[ch[x][1]]^=1,swap(ch[x][0],ch[x][1]);rev[x]^=1;} if(tag[x]){ tag[ch[x][0]]+=tag[x],tag[ch[x][1]]+=tag[x]; mx[ch[x][0]]+=tag[x],mx[ch[x][1]]+=tag[x]; v[ch[x][0]]+=tag[x],v[ch[x][1]]+=tag[x]; tag[x]=0; }}void rotate(int p){ int q=fa[p],y=fa[q],x=(ch[q][1]==p); ch[q][x]=ch[p][!x],fa[ch[q][x]]=q; ch[p][!x]=q;fa[q]=p;fa[p]=y; if(y){ if(ch[y][0]==q)ch[y][0]=p; else ch[y][1]=p; }push_up(q);}void Splay(int x,int tp){ for(int y;y=fa[x];rotate(x)){ if(y==tp)break; if(fa[y]!=tp){ if((ch[y][0]==x)^(ch[fa[y]][0]==y))rotate(x); else rotate(y); } }push_up(x); if(!tp)root=x;}int find(int x,int num){ push_down(x); if(size[ch[x][0]]+1==num)return x; else if(size[ch[x][0]]+1>num)return find(ch[x][0],num); else return find(ch[x][1],num-size[ch[x][0]]-1);}void add(int l,int r,int wei){ int y=find(root,l); Splay(y,0),Splay(find(root,r+2),y); int V=ch[ch[root][1]][0]; tag[V]+=wei,v[V]+=wei;mx[V]+=wei;}void reverse(int l,int r){ int y=find(root,l); Splay(y,0),Splay(find(root,r+2),y); rev[ch[ch[root][1]][0]]^=1;}void get_max(int l,int r){ int y=find(root,l); Splay(y,0),Splay(find(root,r+2),y); printf("%d\n",mx[ch[ch[root][1]][0]]);}int main(){ int op,l,r,wei; scanf("%d%d",&n,&m); root=build(1,n+2); mx[0]=v[1]=v[n+2]=mx[1]=mx[n+2]=-inf; for(int i=1;i<=m;i++){ scanf("%d%d%d",&op,&l,&r); if(op==1)scanf("%d",&wei),add(l,r,wei); else if(op==2)reverse(l,r); else get_max(l,r); }}
0 0
- BZOJ 1251 Splay维护序列
- BZOJ 3323 splay维护序列
- [LCT || splay维护括号序列] BZOJ 4573 [Zjoi2016]大森林
- noi2005 维护序列。 splay
- BZOJ 1251 序列终结者 Splay
- BZOJ 1251 序列终结者 Splay
- BZOJ 1251 序列终结者 Splay
- 【splay】BZOJ 1251 序列终结者
- bzoj 1251: 序列终结者(splay)
- 【BZOJ 1251】序列终结者 splay
- Bzoj 1251: 序列终结者(splay)
- BZOJ 1251: 序列终结者 Splay
- 【BZOJ 1251】序列终结者【裸splay】
- BZOJ 1251: 序列终结者 splay
- bzoj 1251 序列终结者(splay)
- bzoj 1251: 序列终结者 splay
- 【BZOJ】1251 序列终结者 Splay
- 【BZOJ 1798】维护序列
- MFC贴图
- 55. spring boot 服务配置和部署【从零开始学Spring Boot】
- 2017年计划
- Levenberg-Marquardt算法浅谈
- 加载器
- BZOJ 1251 Splay维护序列
- Android——JavaWeb servlet通信
- 字符串的排列
- 《IllegalStateException异常》
- github的基本用法:克隆,上传,查看,删除,分支
- 写论文,复习
- redis 不写磁盘
- 分享一下jqgrid合并单元格
- Idea-2016旅行在四川