//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "带懒标记的线段数": {
        "prefix": "acm-2.6Lazy_Segment_Tree_ask_add",
        "body": [
            "struct node{",
            "    int data,lazy;",
            "};",
            "",
            "void build(const vector<int>&datas,vector<node>&tree,int rt,int left,int right){",
            "    if(left == right){",
            "        tree[rt].data=datas[left];",
            "        return;",
            "    }",
            "    int mid = left+(right-left)/2;",
            "    build(datas,tree,2*rt,left,mid);",
            "    build(datas,tree,2*rt+1,mid+1,right);",
            "    tree[rt].data = tree[2*rt].data+tree[2*rt+1].data;",
            "}",
            "void pushDown(vector<node>&tree,int rt, int len){",
            "    if(tree[rt].lazy != 0){",
            "        tree[rt*2].data += tree[rt].lazy * (len - len/2);",
            "        tree[rt*2].lazy += tree[rt].lazy;",
            "        tree[rt*2+1].data += tree[rt].lazy * (len/2); ",
            "        tree[rt*2+1].lazy += tree[rt].lazy;",
            "        tree[rt].lazy = 0;  ",
            "    }",
            "}",
            "",
            "int query(vector<node>&tree,int rt,int left,int right,int ql,int qr){",
            "    if(ql > right || qr < left){",
            "        return MIN;",
            "    }",
            "    if(ql <= left && qr >= right){",
            "        return tree[rt].data;",
            "    }",
            "    int mid = left+(right-left)/2;",
            "    pushDown(tree,rt,right-left+1);",
            "    int leftsum = query(tree,2*rt,left,mid,ql,qr);",
            "    int rightsum = query(tree,2*rt+1,mid+1,right,ql,qr);",
            "    return leftsum+rightsum;",
            "}",
            "void updata(vector<node>&tree,int rt,int left,int right,int idx,int value){",
            "    if(left == right){",
            "        tree[rt].data = value;",
            "        tree[rt].lazy = 0;",
            "        return;",
            "    }",
            "    int mid = left+(right-left)/2;",
            "    pushDown(tree,rt,right-left+1);",
            "    if(idx<=mid){",
            "        updata(tree,2*rt,left,mid,idx,value);",
            "    }else{",
            "        updata(tree,2*rt+1,mid+1,right,idx,value);",
            "    }",
            "    tree[rt].data = tree[2*rt].data+tree[2*rt+1].data;",
            "}",
            "void updataRange(vector<node>&tree,int rt,int left,int right,int ul,int ur,int value){",
            "    if(ul>right||ur<left) return;",
            "    ",
            "    if(ul<=left && ur >= right){",
            "        tree[rt].data += value * (right - left + 1);",
            "        tree[rt].lazy += value;",
            "        return;",
            "    }",
            "    int mid = left+(right-left)/2;",
            "    pushDown(tree,rt,right-left+1);",
            "    updataRange(tree,2*rt,left,mid,ul,ur,value);",
            "    updataRange(tree,2*rt+1,mid+1,right,ul,ur,value);",
            "    tree[rt].data=tree[2*rt].data+tree[2*rt+1].data;",
            "}"
        ],
        "description": "插入 带懒标记的线段数"
    }
}