编辑代码

#include<iostream>
#include<cstdio>
using namespace std;
template <typename T> struct SegmentTree{
    struct node{
        int l,r;
        T v,tag;
    }t[2000006*4];
    T dat[2000006];
    void pushup(int x){
        t[x].v=op(t[x*2].v,t[x*2+1].v);
    }
    void build(int x,int l,int r){
        t[x].l=l;
        t[x].r=r;
        if(l==r){
            t[x].v=dat[l];
            return;
        }
        int mid=(l+r)/2;
        build(x*2,l,mid);
        build(x*2+1,mid+1,r);
        pushup(x);
    }
    void pushdown(int x){
        if(t[x].tag&&t[x].l!=t[x].r){
            apply(x*2,t[x].tag);
            apply(x*2+1,t[x].tag);
            t[x].tag=0;
        }
    }
    void update(int x,int L,int R,T v){
        int l=t[x].l,r=t[x].r;
        if(L<=l&&r<=R){
            apply(x,v);
            return;
        }
        pushdown(x);
        int mid=(l+r)/2;
        if(L<=mid)update(x*2,L,R,v);
        if(mid+1<=R)update(x*2+1,L,R,v);
        pushup(x);
    }
    T query(int x,int L,int R){
        int l=t[x].l,r=t[x].r;
        if(L<=l&&r<=R){
            return t[x].v;
        }
        pushdown(x);
        int mid=(l+r)/2;
        T tot=tot_init;
        if(L<=mid)tot=q_op(tot,query(x*2,L,R));
        if(mid+1<=R)tot=q_op(tot,query(x*2+1,L,R));
        return tot;
    }
    T op(T x,T y){return x+y;}
    T q_op(T x,T y){return x+y;}
    T tot_init=0;
    void apply(int x,T v){
        t[x].v+=(t[x].r-t[x].l+1)*v;
        t[x].tag+=v;
    }
};
SegmentTree<int>SegTree;
int main(){
    cout<<"hello world"<<endl;

    return 0;
}