1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <map>5 #defineLS l,mid,rt<<16 #defineRS Mid+1,r,rt<<1 |7 using namespacestd;8 Const intmxn=100020;9 intdata[mxn*4];Ten intTRE[MXN],MINI[MXN]; One intADD[MXN];//Lazy Sign A voidPushup (intRT) { -Mini[rt]=min (mini[rt<<1],mini[rt<<1|1]); - } the voidPushdown (intRT) {//passing the lazy tag down - if(add[rt]!=0){ -add[rt<<1]+=Add[rt]; -add[rt<<1|1]+=Add[rt]; +mini[rt<<1]+=Add[rt]; -mini[rt<<1|1]+=Add[rt]; +add[rt]=0;//Mark delivery complete, clear A } at return; - } - voidBuild (intLintRintRT) {//Achievements - if(l==R) { -mini[rt]=Data[l]; - return; in } - intMid= (l+r) >>1; to Build (LS); Build (RS); + pushup (RT); - return; the } * voidUpdate_point (intPintXintLintRintRT) {//single-point update $ if(l==R) {Panax Notoginsengmini[rt]=x; - return; the } + intMid= (l+r) >>1; A if(p<=mid) Update_point (P,X,LS); the ElseUpdate_point (p,x,rs); + return; - } $ voidUpdate_area (intLintRintCintLintRintRT) {//Zone Updates $ if(L<=l && r<=R) { -add[rt]+=C; -mini[rt]+=C; the } - pushdown (RT);Wuyi intMid= (l+r) >>1; the if(l<=mid) Update_area (L,R,C,LS); - if(r>mid) Update_area (L,R,C,RS); Wu pushup (RT); - return; About } $ intQueryintLintRintLintRintRT) {//Area Query - if(L<=l && r<=r)returnMini[rt]; - intMid= (l+r) >>1; - intans=1000000; A if(L<=mid) ans=min (ans,query (l,r,ls)); + if(Mid<r) ans=min (ans,query (l,r,rs)); the returnans; - } $ intMain () { the the the the}
Save the Segment tree template