Save the Segment tree template

Source: Internet
Author: User

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

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.