Bzoj 1588 [HNOI2002] turnover statistics

Source: Internet
Author: User

1251: Sequence Terminator Time Limit: Sec Memory Limit: 162 MB
Submit: 3773 Solved: 1579
[Submit] [Status] [Discuss] Description

There are many questions on the web, that is, given a sequence, you need to support several operations: A, B, C, D. Look at another question, and another sequence to support several operations: D, C, B, A. In particular, we have someone here, out of the mock test, incredibly also out of one such, really no technical content ... So I also out of a problem, I came out this purpose is to let everyone do this topic has a "library" can rely on, there is no other meaning. This problem is called sequence Terminator. "Problem description" given a sequence of length n, the element of each sequence is an integer (nonsense). To support the following three actions: 1. Add all the numbers in this range [L,r] to V. 2. Flip [l,r] this interval, e.g. 1 2 3 4 to 4 3 2 1. 3. Ask for the maximum value in this interval [l,r]. At the very beginning, all elements are 0.

Input

The first row of two integers n,m. M is the number of operations. The following m lines, with a maximum of four integers per line, are k,l,r,v. K is the number of operations, if not the 1th operation then there are only two digits after K.

Output

For each of the 3rd operations, give the correct answer.

Sample Input4 4
1 1 3 2
1 2 4-1
2 1 3
3 2 4

 Sample Output2
"Data Range"
n<=50000,m<=100000.

 HINT

 

Source

Splay processing.

#include <cstdio>#include<iostream>#defineIn inline#defineR Registerusing namespacestd;Const intn=1e5+Ten;intn,m,rt,siz[n],fa[n],c[n][2];BOOLRev[n];intTag[n],mx[n],w[n];inintRead () {Rintx=0; RBOOLf=1; RCharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=0; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x= (x<<3) + (x<<1) +ch-'0'; ch=GetChar ();} returnf?x:-x;} InchvoidUpdata (intk) {    intl=c[k][0],r=c[k][1]; SIZ[K]=siz[l]+siz[r]+1; MX[K]=Max (Mx[l],mx[r]); MX[K]=Max (mx[k],w[k]);} InchvoidPushdown (intk) {    int&l=c[k][0],&r=c[k][1]; if(Tag[k]) {if(l) tag[l]+=tag[k],mx[l]+=tag[k],w[l]+=Tag[k]; if(r) tag[r]+=tag[k],mx[r]+=tag[k],w[r]+=Tag[k]; TAG[K]=0; }    if(Rev[k]) {swap (L,R); REV[L]^=1; rev[r]^=1; REV[K]=0; }}invoidRotateintXint&k) {    inty=fa[x],z=Fa[y],l,r; L= (c[y][1]==X); r=l^1; if(y==k) k=x; Elsec[z][c[z][1]==y]=x; FA[X]=z;fa[y]=x;fa[c[x][r]]=y; C[Y][L]=c[x][r];c[x][r]=y; Updata (y); Updata (x);} InchvoidSplay (intXint&k) {     while(x!=k) {        inty=fa[x],z=Fa[y]; if(y!=k) {            if((c[z][0]==y) ^ (c[y][0]==x)) rotate (x,k); Elserotate (y,k);    } rotate (x,k); }}voidBuildintLintRintf) {    if(L>r)return ; intMid=l+r>>1; C[f][mid>=f]=mid; Siz[mid]=1; fa[mid]=F; if(L==R)return ; Build (L,mid-1, mid); Build (mid+1, R,mid); Updata (mid);}intFindintKintRK)    {pushdown (k); intl=c[k][0],r=c[k][1]; if(siz[l]+1==RK)returnK; returnSiz[l]>=rk?find (L,RK): Find (r,rk-siz[l]-1);} InchvoidAddintLintRintv) {    intX=find (rt,l), Y=find (rt,r+2); Splay (X,RT); Splay (y,c[x][1]); int&z=c[y][0]; TAG[Z]+=v;mx[z]+=v;w[z]+=v;} InchvoidRever (intLintR) {    intX=find (rt,l), Y=find (rt,r+2); Splay (X,RT); Splay (y,c[x][1]); rev[c[y][0]]^=1;} InchintQmaxintLintR) {    intX=find (rt,l), Y=find (rt,r+2); Splay (X,RT); Splay (y,c[x][1]); returnmx[c[y][0]];}intMain () {mx[0]=-0x7fffffff;//Note that there are negative numbers, so mx[0] to define the minimum valueN=read (); m=read (); Build (1, n+2,0); rt=n+3>>1;  for(intI=0, opt,l,r,v;i<m;i++) {opt=read (); L=read (); r=read (); Switch(opt) { Case 1: V=read (); Add (l,r,v); Break;  Case 2: Rever (L,R); Break;  Case 3:p rintf ("%d\n", Qmax (l,r)); Break; }    }    return 0;}

 

Bzoj 1588 [HNOI2002] turnover statistics

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.