Advertising:
#include <stdio.h>int main(){ puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/44037685");}
Exercises
Sort and insert the segment tree first
Use the segment tree to manipulate the entire range at a time.
It then maintains which intervals are overrun and assigns values to the interval.
Overflow handling:
The left endpoint of an interval is greater than the maximum value, or the right endpoint is less than the minimum value
Then this interval should be covered.
Overlay, add stunts:
Multiply 0+x is covered into X.
Pruning? :
An interval right endpoint ≤ Maximum value, or left endpoint ≥ The minimum value, then return
A group of data:
3 3 3044- 9999@ 3- 13672850127
Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 101000#define LS (note<<1)#define RS (note<<1|1)using namespace STD;structlsh{Long LongXintPBOOL operator< (ConstLSH &a)Const{returnx<a.x;}voidReadintN) {scanf("%lld", &x), P=n;}} Lsh[n];structopt{intFLong LongAvoidReadintP) {scanf("%lld", &a), F=p;}} Opt[n];intN,m;Long LongL,r,ans[n];structksd{intL,r,s;Long LongA,b,c;Long LongL,r,lx,rx;} s[n<<2];inline voidPushdown (intNote//multiplication C does not affect other{if(S[note]. c!=1) {S[note]. L*=s[note]. C S[note]. R*=s[note]. Cif(S[NOTE].L<S[NOTE].R) {S[ls]. A*=s[note]. C S[ls]. B*=s[note]. C S[ls]. C*=s[note]. C S[RS]. A*=s[note]. C S[RS]. B*=s[note]. C S[RS]. C*=s[note]. C } S[note]. C=1; }if(S[note]. A) {S[note]. L+=s[note]. A S[note]. R+=s[note]. Aif(S[NOTE].L<S[NOTE].R) {S[ls]. A+=s[note]. A S[RS]. A+=s[note]. A } S[note]. A=0; }if(S[note]. B) {S[note]. L+=s[note]. B*S[NOTE].LX; S[note]. R+=s[note]. B*s[note].rx;if(S[NOTE].L<S[NOTE].R) {S[ls]. B+=s[note]. B S[RS]. B+=s[note]. B } S[note]. b=0; }return;}inline voidPushup (intNote) {S[note]. L=s[ls]. L S[note]. R=S[RS]. Rreturn;}voidBuildintNoteintLintR) {s[note].l=l,s[note].r=r; S[note]. C=1;if(L==R) {S[note]. L=s[note]. r=s[note].lx=s[note].rx=lsh[l].x; S[NOTE].S=LSH[L].P;return; }intMid=l+r>>1; Build (Ls,l,mid), Build (rs,mid+1, R); S[note].lx=s[ls].lx,s[note].rx=s[rs].rx; Pushup (note);return;}voidAddintNoteLong LongWintf) {if(f==0) S[note]. A+=w;ElseS[note]. B+=w; Pushdown (note);}voidMulintNoteLong LongW) {S[note]. A*=w,s[note]. B*=w,s[note]. C*=w; Pushdown (note);}//void cover (x), Mul (0), add (x,0)voidKeepintNote) {pushdown (note);if(S[note]. L>r) {S[note]. A=r; S[note]. b=0; S[note]. C=0; Pushdown (note);return; }if(S[note]. R<L) {S[note]. A=l; S[note]. b=0; S[note]. C=0; Pushdown (note);return; }if(S[note]. R<=r&&s[note]. L>=L)return;intMid=s[note].l+s[note].r>>1; Keep (LS), keep (RS), pushup (note);}voidDfsintNote) {pushdown (note);if(S[NOTE].L==S[NOTE].R) {Ans[s[note].s]=s[note]. Lreturn; } dfs (LS), DFS (RS);}Charss[5];intMain () {Freopen ("Test.in","R", stdin);intIscanf("%d%lld%lld", &m,&l,&r); for(i=1; i<=m;i++) {scanf('%s ', SS);if(ss[0]==' + ') Opt[i].read (1);Else if(ss[0]=='-') Opt[i].read (2);Else if(ss[0]==' * ') Opt[i].read (3);Else if(ss[0]==' @ ') Opt[i].read (4); }scanf("%d", &n); for(i=1; i<=n;i++) Lsh[i].read (i); Sort (lsh+1, lsh+n+1); Build1,1, n); for(i=1; i<=m;i++) {if(opt[i].f==1) Add (1, OPT[I].A,0);Else if(opt[i].f==2) Add (1,-OPT[I].A,0);Else if(opt[i].f==3) Mul (1, OPT[I].A);Else if(opt[i].f==4) Add (1, OPT[I].A,1); Keep1); } DFS (1); for(i=1; i<=n;i++)printf("%lld\n", Ans[i]);return 0;}
"BZOJ3878" "Ahoi2014" strange Calculator maintenance interval properties. Segment Tree