正文
增加 4 行删除 3 行
21 行未改动2223242526272829303132333411 行未改动46474849505152535427 行未改动828384858687888945 行未改动21 行未改动void pushdown(int p) //标志性的线段树代码{if (tree[p].lazy){int mid =(tree[p].right - tree[p].left + 1);tree[p << 1].lazy += tree[p].lazy; //lazy传给左儿子tree[p << 1].data += tree[p].lazy * (mid - tree[p << 1].left + 1); //更新左儿子的datatree[p << 1 | 1].lazy += tree[p].lazy; //lazy传给右儿子tree[p << 1 | 1].data += tree[p].lazy * (tree[p << 1].right - mid); //更新右儿子的datatree[p].lazy = 0; //父节点的lazy清零}}11 行未改动int mid = L + R >> 1; //(L+R)/2build(p << 1, L, mid); //递归建左子树build(p << 1 | 1, mid + 1, R); ////递归建右子树tree[p].data = tree[p >> 1].data + tree[p << 1 | 1].data; //回溯时维护数据信息}int query(int p, int L, int R) //在以p为根节点的线段树中,查询区间[L,R]{27 行未改动cout.tie(0);return 0;}```线段树练习:https://www.luogu.com.cn/problem/P337245 行未改动21 行未改动2223242526272829303132333411 行未改动46474849505152535427 行未改动82838485868788899045 行未改动21 行未改动void pushdown(int p) //标志性的线段树代码{if (tree[p].lazy){int mid = tree[p].left + tree[p].right >> 1;tree[p << 1].lazy += tree[p].lazy; //lazy传给左儿子tree[p << 1].data += tree[p].lazy * (mid - tree[p << 1].left + 1); //更新左儿子的datatree[p << 1 | 1].lazy += tree[p].lazy; //lazy传给右儿子tree[p << 1 | 1].data += tree[p].lazy * (tree[p << 1 | 1].right - mid); //更新右儿子的datatree[p].lazy = 0; //父节点的lazy清零}}11 行未改动int mid = L + R >> 1; //(L+R)/2build(p << 1, L, mid); //递归建左子树build(p << 1 | 1, mid + 1, R); ////递归建右子树tree[p].data = tree[p << 1].data + tree[p << 1 | 1].data; //回溯时维护数据信息}int query(int p, int L, int R) //在以p为根节点的线段树中,查询区间[L,R]{27 行未改动cout.tie(0);return 0;}```线段树练习:https://www.luogu.com.cn/problem/P337245 行未改动