本文主要是介绍[BZOJ1251] 序列终结者,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
传送门
http://www.lydsy.com/JudgeOnline/problem.php?id=1251
题目大意
支持
1.区间+-
2.区间翻转
3.查询区间最大值
题解
Splay模板题
注意+-标记的下放
这个节点打上+-标记表明该节点的权值和最值已被处理过
constmaxn=100005;
varw: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;
beginif w[a,7]<>0 then beginc:=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 beginif 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;
beginif a>b then exit(a) else exit(b);
end;procedure rotate(a,kind:longint);
var b,unkind:longint;
beginpushdown(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]<>-1thenif w[w[a,3],1]=bthen w[w[a,3],1]:=aelse 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;
beginwhile w[a,3]<>goal dobeginb:=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)elseif w[w[b,3],kind]=bthen begin rotate(b,kind); rotate(a,kind); endelse begin rotate(a,kind); rotate(a,unkind); end;end;if goal=-1 then root:=a;
end;procedure init(a:longint);
var tt,fa:longint;
begintt:=root;while tt<>-1 dobegin 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;
begintt:=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) dobeginif 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;beginreadln(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 doinit(i);ans[0]:=0;for i:=1 to m dobeginread(a);case a of1: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] dowriteln(ans[i]);
end.
这篇关于[BZOJ1251] 序列终结者的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!