版本比较
浅析线段树实现
正文
增加 2 行删除 2 行
160 行未改动全部展开16116216316416516616716816933 行未改动203204205206207208209210211198 行未改动全部展开160 行未改动全部展开if (r & 1) v = r, modify(--r, val);// 以下 pushup 建议照抄,这是目前最简单的写法,注意要先上移再 pushupdo pushup(u >>= 1); while (l == r && u);do pushup(v >>= 1); while (l == r && v);}}```### 完整实现33 行未改动if (l & 1) u = l, modify(l++, val);if (r & 1) v = r, modify(--r, val);do pushup(u >>= 1); while (l == r && u);do pushup(v >>= 1); while (l == r && v);}}intl query(int l, int r) {l += n, r += n + 1;for (int i = __lg(n) + 1; i; i--) pushdown(l >> i), pushdown(r >> i);198 行未改动全部展开160 行未改动全部展开16116216316416516616716816933 行未改动203204205206207208209210211198 行未改动全部展开160 行未改动全部展开if (r & 1) v = r, modify(--r, val);// 以下 pushup 建议照抄,这是目前最简单的写法,注意要先上移再 pushupdo pushup(u >>= 1); while (l == r && u);do pushup(v >>= 1); while (l == r && v);}}```### 完整实现33 行未改动if (l & 1) u = l, modify(l++, val);if (r & 1) v = r, modify(--r, val);do pushup(u >>= 1); while (l == r && u);do pushup(v >>= 1); while (l == r && v);}}intl query(int l, int r) {l += n, r += n + 1;for (int i = __lg(n) + 1; i; i--) pushdown(l >> i), pushdown(r >> i);198 行未改动全部展开