Bzoj 1251: Sequence Terminator (splay template title)

Source: Internet
Author: User

Face (too naked, not looking)

is to maintain an interval plus, interval rollover, and interval maximum.

Post a style can always use

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 #defineN 1000006 #defineXX GetChar ()7 using namespacestd;8 intch[n][2],fa[n],rev[n],ad[n],b[n],mx[n],n,m,rt,sz[n],tot,a[n];9InlineintRead ()Ten{intflag=1;CharC=xx; for(;c<'0'|| C>'9'; c=xx) {if(c=='-') flag=-1;} One     intx=0; for(; c>='0'&&c<='9'; x=x*Ten+c- -, c=xx);returnx*Flag; A } -InlinevoidMark_rev (intx) {if(!x)return; Swap (ch[x][0],ch[x][1]), rev[x]^=1;} -InlinevoidMark_add (intXintV) {if(!x)return; b[x]+=v,mx[x]+=v;ad[x]+=v;} theInlinevoidPush_down (intx) -{if(Rev[x]) {Mark_rev (ch[x][0]), Mark_rev (ch[x][1]), rev[x]^=1;} -     if(Ad[x]) {Mark_add (ch[x][0],ad[x]), Mark_add (ch[x][1],ad[x]), ad[x]=0;} - } +InlinevoidPUSH_UP (intx) -{mx[x]=b[x],sz[x]=1;if(ch[x][0]) Mx[x]=max (mx[x],mx[ch[x][0]]), sz[x]+=sz[ch[x][0]]; +     if(ch[x][1]) Mx[x]=max (mx[x],mx[ch[x][1]]), sz[x]+=sz[ch[x][1]]; A } at voidRotintx) -{inty=fa[x],d=ch[y][1]==x; -fa[ch[x][d^1]]=y,ch[y][d]=ch[x][d^1]; -     if(Fa[y]) ch[fa[y]][ch[fa[y]][1]==y]=x; -fa[x]=fa[y];fa[y]=x;ch[x][d^1]=y; Push_up (y); - } in voidSplay (intXintgoal) -{ints=1, i=x;a[1]=x; to      while(Fa[i]) a[++s]= (I=fa[i]); while(s) push_down (a[s--]); +      while(Fa[x]!=goal) {intY=FA[X];if(Fa[y]==goal) {rot (x);Continue;} -     if((ch[y][0]==x) ^ (ch[fa[y]][0]==y)) rot (y);Elserot (x); rot (x);} thePUSH_UP (x);if(goal==0) rt=x; * } $ intBuilding (intLintRintf)Panax Notoginseng{intX=++tot,mid = (l+r) >>1; -fa[x]=f;b[x]=0;if(L<mid) ch[x][0]=building (l,mid-1, x);  the     if(R>mid) ch[x][1]=building (mid+1, r,x); PUSH_UP (x);returnx; + } A intFind_kth (intk) the{intx=rt,tmp; +      while(1)  -{Push_down (x); tmp=sz[ch[x][0]]+1;if(k==tmp)returnx; $         if(k<tmp) x=ch[x][0];ElseK-=tmp, x=ch[x][1]; $     } - } - voidADD (intLintRintv) the{splay (find_kth (L),0); Splay (Find_kth (r+2), RT); -     intx=ch[ch[rt][1]][0]; Mark_add (x,v);Wuyi } the voidReverse (intLintR) -{splay (find_kth (L),0); Splay (Find_kth (r+2), RT); Wu     intx=ch[ch[rt][1]][0]; Mark_rev (x); - } About intQuery_max (intLintR) ${splay (find_kth (L),0); Splay (Find_kth (r+2), RT); -     returnmx[ch[ch[rt][1]][0]]; - } - intMain () A{N=read (), M=read ();intk,l,r,v,i; +Rt=building (0, n+1, rt=0); the      for(i=1; i<=m;i++)  -{k=read (); $         if(k==1) {L=read (), R=read (), v=read (), ADD (l,r,v);} the         if(k==2) {L=read (), r=read (), Reverse (l,r);} the         if(k==3) {L=read (), R=read (), printf ("%d\n", Query_max (L,r));} the     } the     return 0; -}
Templates

is a little big constant unhappy.

Bzoj 1251: Sequence Terminator (splay template title)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.