Skip to content

Commit e2cdebb

Browse files
authored
Refactor lazy segment tree apply and update methods
1 parent f7a8295 commit e2cdebb

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

library/data_structures_[l,r)/lazy_seg_tree.hpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ struct seg_tree {
1111
for (int i = n - 1; i >= 1; i--)
1212
tree[i] = op(tree[2 * i], tree[2 * i + 1]);
1313
}
14-
void apply(ll change, int tl, int tr, int v) {
15-
tree[v] += (tr - tl) * change;
16-
if (v < n) lazy[v] += change;
14+
void apply(ll d, int tl, int tr, int v) {
15+
tree[v] += (tr - tl) * d;
16+
if (v < n) lazy[v] += d;
1717
}
1818
void push(int tl, int tm, int tr, int v) {
1919
if (lazy[v]) {
@@ -22,18 +22,17 @@ struct seg_tree {
2222
lazy[v] = 0;
2323
}
2424
}
25-
void update(int l, int r, ll change) {
26-
update(l, r, change, 0, n, 1);
25+
void update(int l, int r, ll d) {
26+
update(l, r, d, 0, n, 1);
2727
}
28-
void update(int l, int r, ll change, int tl, int tr,
29-
int v) {
28+
void update(int l, int r, ll d, int tl, int tr, int v) {
3029
if (r <= tl || tr <= l) return;
3130
if (l <= tl && tr <= r)
32-
return apply(change, tl, tr, v);
31+
return apply(d, tl, tr, v);
3332
int tm = split(tl, tr);
3433
push(tl, tm, tr, v);
35-
update(l, r, change, tl, tm, 2 * v);
36-
update(l, r, change, tm, tr, 2 * v + 1);
34+
update(l, r, d, tl, tm, 2 * v);
35+
update(l, r, d, tm, tr, 2 * v + 1);
3736
tree[v] = op(tree[2 * v], tree[2 * v + 1]);
3837
}
3938
ll query(int l, int r) { return query(l, r, 0, n, 1); }

0 commit comments

Comments
 (0)