[BZOJ1251] 序列终结者
来源:互联网 发布:linux如何卸载jdk 编辑:程序博客网 时间:2024/05/17 02:55
传送门
http://www.lydsy.com/JudgeOnline/problem.php?id=1251
题目大意
支持
1.区间+-
2.区间翻转
3.查询区间最大值
题解
Splay模板题
注意+-标记的下放
这个节点打上+-标记表明该节点的权值和最值已被处理过
const maxn=100005;var w:array[-1..maxn,1..8]of longint; ans:array[0..maxn]of longint; i,j,k:longint; n,m,sum,root,a,b,c,d:longint;procedure pushdown(a:longint);var c:longint;begin if w[a,7]<>0 then begin c:=w[a,1]; w[a,1]:=w[a,2]; w[a,2]:=c; w[a,7]:=0; w[w[a,1],7]:=w[w[a,1],7] xor 1; w[w[a,2],7]:=w[w[a,2],7] xor 1; end; if w[a,8]<>0 then begin if w[a,1]<>-1 then begin inc(w[w[a,1],8],w[a,8]); inc(w[w[a,1],5],w[a,8]); inc(w[w[a,1],6],w[a,8]); end; if w[a,2]<>-1 then begin inc(w[w[a,2],8],w[a,8]); inc(w[w[a,2],5],w[a,8]); inc(w[w[a,2],6],w[a,8]); end; w[a,8]:=0; end;end;function max(a,b:longint):longint;begin if a>b then exit(a) else exit(b);end;procedure rotate(a,kind:longint);var b,unkind:longint;begin pushdown(b); pushdown(a); b:=w[a,3]; unkind:=kind xor 3; w[a,4]:=w[b,4]; dec(w[b,4],1+w[w[a,kind],4]); w[w[a,unkind],3]:=b; w[b,kind]:=w[a,unkind]; w[a,unkind]:=b; w[a,3]:=w[b,3]; w[b,3]:=a; if w[a,3]<>-1 then if w[w[a,3],1]=b then w[w[a,3],1]:=a else w[w[a,3],2]:=a; w[b,5]:=max(max(w[w[b,1],5],w[w[b,2],5]),w[b,6]); w[a,5]:=max(max(w[w[a,1],5],w[w[a,2],5]),w[a,6]);end;procedure splay(a,goal:longint);var kind,b,unkind:longint;begin while w[a,3]<>goal do begin b:=w[a,3]; if w[b,1]=a then kind:=1 else kind:=2; unkind:=kind xor 3; if w[b,3]=goal then rotate(a,kind) else if w[w[b,3],kind]=b then begin rotate(b,kind); rotate(a,kind); end else begin rotate(a,kind); rotate(a,unkind); end; end; if goal=-1 then root:=a;end;procedure init(a:longint);var tt,fa:longint;begin tt:=root; while tt<>-1 do begin fa:=tt; inc(w[tt,4]); tt:=w[tt,2]; end; inc(sum); w[sum,1]:=-1; w[sum,2]:=-1; w[sum,3]:=fa; w[sum,4]:=1; w[sum,5]:=0; w[sum,6]:=0; w[sum,7]:=0; w[sum,8]:=0; if a=n+1 then w[sum,6]:=-maxlongint; splay(sum,-1);end;function getkth(a:longint):longint;var tt:longint;begin tt:=root; if (w[tt,7]<>0)or(w[tt,8]<>0) then pushdown(tt); while (w[w[tt,1],4]>=a)or(a>=w[w[tt,1],4]+2) do begin if a<=w[w[tt,1],4] then tt:=w[tt,1] else begin dec(a,w[w[tt,1],4]+1); tt:=w[tt,2]; end; if (w[tt,7]<>0)or(w[tt,8]<>0) then pushdown(tt); end; exit(tt);end;begin readln(n,m); sum:=1; root:=1; w[-1,5]:=-maxlongint; w[-1,6]:=-maxlongint; w[1,1]:=-1; w[1,2]:=-1; w[1,3]:=-1; w[1,4]:=1; w[1,5]:=0; w[1,6]:=-maxlongint; w[1,7]:=0; w[1,8]:=0; for i:=1 to n+1 do init(i); ans[0]:=0; for i:=1 to m do begin read(a); case a of 1:begin readln(b,c,d); splay(getkth(b),-1); splay(getkth(c+2),root); inc(w[w[w[root,2],1],8],d); inc(w[w[w[root,2],1],5],d); inc(w[w[w[root,2],1],6],d); end; 2:begin readln(b,c); splay(getkth(b),-1); splay(getkth(c+2),root); w[w[w[root,2],1],7]:=w[w[w[root,2],1],7] xor 1; end; 3:begin readln(b,c); splay(getkth(b),-1); splay(getkth(c+2),root); pushdown(w[w[root,2],1]); inc(ans[0]); ans[ans[0]]:=w[w[w[root,2],1],5]; end; end; end; for i:=1 to ans[0] do writeln(ans[i]);end.
0 0
- bzoj1251 序列终结者
- [BZOJ1251] 序列终结者
- [BZOJ1251]序列终结者
- [BZOJ1251]序列终结者
- BZOJ1251序列终结者
- bzoj1251 序列终结者
- bzoj1251 序列终结者
- BZOJ1251: 序列终结者
- bzoj1251: 序列终结者
- 【BZOJ1251】序列终结者
- BZOJ1251 序列终结者
- 【BZOJ1251】【splay】序列终结者
- splay bzoj1251序列终结者
- [Bzoj1251]序列终结者 (Splay)
- 【bzoj1251】序列终结者 Splay
- 【bzoj1251】【序列终结者】【splay】
- bzoj1251: 序列终结者 splay
- [BZOJ1251]序列终结者 Splay
- 观雪
- 愁
- Activity启动流程阅读
- ST学习笔记
- RxAndroid 应用(三)(简易天气App之Observable内存泄露)
- [BZOJ1251] 序列终结者
- JSON和XML的比较
- 惜
- 图像算法---磨皮算法研究汇总
- OC中NSString/NSArray/#define宏定义的解析
- 关于Android Studio 编译classpath ‘gradle:2.0.0-alpha3’出错
- 《IOS 9 支付宝 and 微信 支付的集成》
- Android中常用控件(1)-TextView
- 途牛原创|途牛Android App的插件实现