From e2cdebb802168ee6c2cc16dc6523fb33c8643315 Mon Sep 17 00:00:00 2001 From: Luke Videckis Date: Thu, 22 Jan 2026 21:16:05 -0700 Subject: [PATCH 1/8] Refactor lazy segment tree apply and update methods --- .../data_structures_[l,r)/lazy_seg_tree.hpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/library/data_structures_[l,r)/lazy_seg_tree.hpp b/library/data_structures_[l,r)/lazy_seg_tree.hpp index 4f6b755a..81a7135d 100644 --- a/library/data_structures_[l,r)/lazy_seg_tree.hpp +++ b/library/data_structures_[l,r)/lazy_seg_tree.hpp @@ -11,9 +11,9 @@ struct seg_tree { for (int i = n - 1; i >= 1; i--) tree[i] = op(tree[2 * i], tree[2 * i + 1]); } - void apply(ll change, int tl, int tr, int v) { - tree[v] += (tr - tl) * change; - if (v < n) lazy[v] += change; + void apply(ll d, int tl, int tr, int v) { + tree[v] += (tr - tl) * d; + if (v < n) lazy[v] += d; } void push(int tl, int tm, int tr, int v) { if (lazy[v]) { @@ -22,18 +22,17 @@ struct seg_tree { lazy[v] = 0; } } - void update(int l, int r, ll change) { - update(l, r, change, 0, n, 1); + void update(int l, int r, ll d) { + update(l, r, d, 0, n, 1); } - void update(int l, int r, ll change, int tl, int tr, - int v) { + void update(int l, int r, ll d, int tl, int tr, int v) { if (r <= tl || tr <= l) return; if (l <= tl && tr <= r) - return apply(change, tl, tr, v); + return apply(d, tl, tr, v); int tm = split(tl, tr); push(tl, tm, tr, v); - update(l, r, change, tl, tm, 2 * v); - update(l, r, change, tm, tr, 2 * v + 1); + update(l, r, d, tl, tm, 2 * v); + update(l, r, d, tm, tr, 2 * v + 1); tree[v] = op(tree[2 * v], tree[2 * v + 1]); } ll query(int l, int r) { return query(l, r, 0, n, 1); } From 2166a3d08575fddb0d611cd80f66287ebb777835 Mon Sep 17 00:00:00 2001 From: Luke Videckis Date: Thu, 22 Jan 2026 21:18:28 -0700 Subject: [PATCH 2/8] Refactor update method for lazy segment tree --- library/data_structures_[l,r)/lazy_seg_tree.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/data_structures_[l,r)/lazy_seg_tree.hpp b/library/data_structures_[l,r)/lazy_seg_tree.hpp index 81a7135d..235b16a1 100644 --- a/library/data_structures_[l,r)/lazy_seg_tree.hpp +++ b/library/data_structures_[l,r)/lazy_seg_tree.hpp @@ -27,8 +27,7 @@ struct seg_tree { } void update(int l, int r, ll d, int tl, int tr, int v) { if (r <= tl || tr <= l) return; - if (l <= tl && tr <= r) - return apply(d, tl, tr, v); + if (l <= tl && tr <= r) return apply(d, tl, tr, v); int tm = split(tl, tr); push(tl, tm, tr, v); update(l, r, d, tl, tm, 2 * v); From 820635c2f65eccfda92d1128096bfcea49c7ec12 Mon Sep 17 00:00:00 2001 From: Luke Videckis Date: Thu, 22 Jan 2026 21:20:36 -0700 Subject: [PATCH 3/8] Move operation function inside seg_tree struct --- library/data_structures_[l,r)/lazy_seg_tree.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/data_structures_[l,r)/lazy_seg_tree.hpp b/library/data_structures_[l,r)/lazy_seg_tree.hpp index 235b16a1..278df6e0 100644 --- a/library/data_structures_[l,r)/lazy_seg_tree.hpp +++ b/library/data_structures_[l,r)/lazy_seg_tree.hpp @@ -1,7 +1,7 @@ #pragma once #include "seg_tree_midpoint.hpp" -ll op(ll vl, ll vr) { return vl + vr; } struct seg_tree { + ll op(ll vl, ll vr) { return vl + vr; } int n; vector tree, lazy; seg_tree(int n): n(n), tree(2 * n), lazy(n) {} From 60eb693d0cec1cc8398c14f6497951f9a8fd3d61 Mon Sep 17 00:00:00 2001 From: Luke Videckis Date: Thu, 22 Jan 2026 21:22:10 -0700 Subject: [PATCH 4/8] Update lazy_seg_tree.hpp --- .../data_structures_[l,r]/lazy_seg_tree.hpp | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/library/data_structures_[l,r]/lazy_seg_tree.hpp b/library/data_structures_[l,r]/lazy_seg_tree.hpp index 33377ce5..c9868fe0 100644 --- a/library/data_structures_[l,r]/lazy_seg_tree.hpp +++ b/library/data_structures_[l,r]/lazy_seg_tree.hpp @@ -1,7 +1,7 @@ #pragma once #include "seg_tree_midpoint.hpp" -ll op(ll vl, ll vr) { return vl + vr; } struct seg_tree { + ll op(ll vl, ll vr) { return vl + vr; } int n; vector tree, lazy; seg_tree(int n): n(n), tree(2 * n), lazy(n) {} @@ -11,9 +11,9 @@ struct seg_tree { for (int i = n - 1; i >= 1; i--) tree[i] = op(tree[2 * i], tree[2 * i + 1]); } - void apply(ll change, int tl, int tr, int v) { - tree[v] += (tr - tl + 1) * change; - if (v < n) lazy[v] += change; + void apply(ll d, int tl, int tr, int v) { + tree[v] += (tr - tl + 1) * d; + if (v < n) lazy[v] += d; } void push(int tl, int tm, int tr, int v) { if (lazy[v]) { @@ -22,18 +22,16 @@ struct seg_tree { lazy[v] = 0; } } - void update(int l, int r, ll change) { - update(l, r, change, 0, n - 1, 1); + void update(int l, int r, ll d) { + update(l, r, d, 0, n - 1, 1); } - void update(int l, int r, ll change, int tl, int tr, - int v) { + void update(int l, int r, ll d, int tl, int tr, int v) { if (r < tl || tr < l) return; - if (l <= tl && tr <= r) - return apply(change, tl, tr, v); + if (l <= tl && tr <= r) return apply(d, tl, tr, v); int tm = split(tl, tr); push(tl, tm, tr, v); - update(l, r, change, tl, tm, 2 * v); - update(l, r, change, tm + 1, tr, 2 * v + 1); + update(l, r, d, tl, tm, 2 * v); + update(l, r, d, tm + 1, tr, 2 * v + 1); tree[v] = op(tree[2 * v], tree[2 * v + 1]); } ll query(int l, int r) { From 5af37a56da8600280852e21fe41311b246db2d01 Mon Sep 17 00:00:00 2001 From: Luke Videckis Date: Thu, 22 Jan 2026 21:24:19 -0700 Subject: [PATCH 5/8] Fix cppcheck suppression for lazy_seg_tree.hpp --- tests/.config/.cppcheck_suppression_list | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/.config/.cppcheck_suppression_list b/tests/.config/.cppcheck_suppression_list index 21d6bced..b3fdf194 100644 --- a/tests/.config/.cppcheck_suppression_list +++ b/tests/.config/.cppcheck_suppression_list @@ -61,5 +61,5 @@ unusedFunction:../kactl/content/number-theory/ModPow.h:13 unusedFunction:../kactl/stress-tests/utilities/genTree.h:49 containerOutOfBounds:../library/data_structures_[l,r)/uncommon/permutation_tree.hpp:85 ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/bit.hpp:5 -ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/lazy_seg_tree.hpp:4 +ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/lazy_seg_tree.hpp:3 shiftTooManyBits:../library/math/matrix_related/xor_basis_ordered.hpp:18 From 3c991826a9f24d5edf7fbb32a42902e45d66ba66 Mon Sep 17 00:00:00 2001 From: Luke Videckis Date: Thu, 22 Jan 2026 21:27:49 -0700 Subject: [PATCH 6/8] Refactor operation function in lazy segment tree --- library/data_structures_[l,r)/lazy_seg_tree.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/data_structures_[l,r)/lazy_seg_tree.hpp b/library/data_structures_[l,r)/lazy_seg_tree.hpp index 278df6e0..235b16a1 100644 --- a/library/data_structures_[l,r)/lazy_seg_tree.hpp +++ b/library/data_structures_[l,r)/lazy_seg_tree.hpp @@ -1,7 +1,7 @@ #pragma once #include "seg_tree_midpoint.hpp" +ll op(ll vl, ll vr) { return vl + vr; } struct seg_tree { - ll op(ll vl, ll vr) { return vl + vr; } int n; vector tree, lazy; seg_tree(int n): n(n), tree(2 * n), lazy(n) {} From 75aa1f38217221cca83434135313ae7a44c7a862 Mon Sep 17 00:00:00 2001 From: Luke Videckis Date: Thu, 22 Jan 2026 21:28:10 -0700 Subject: [PATCH 7/8] Update lazy_seg_tree.hpp --- library/data_structures_[l,r]/lazy_seg_tree.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/data_structures_[l,r]/lazy_seg_tree.hpp b/library/data_structures_[l,r]/lazy_seg_tree.hpp index c9868fe0..6c67949b 100644 --- a/library/data_structures_[l,r]/lazy_seg_tree.hpp +++ b/library/data_structures_[l,r]/lazy_seg_tree.hpp @@ -1,7 +1,7 @@ #pragma once #include "seg_tree_midpoint.hpp" +ll op(ll vl, ll vr) { return vl + vr; } struct seg_tree { - ll op(ll vl, ll vr) { return vl + vr; } int n; vector tree, lazy; seg_tree(int n): n(n), tree(2 * n), lazy(n) {} From f64522ab4f377589f243e6a004f848de9992662a Mon Sep 17 00:00:00 2001 From: Luke Videckis Date: Thu, 22 Jan 2026 21:28:36 -0700 Subject: [PATCH 8/8] Update cppcheck suppression for lazy_seg_tree.hpp --- tests/.config/.cppcheck_suppression_list | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/.config/.cppcheck_suppression_list b/tests/.config/.cppcheck_suppression_list index b3fdf194..21d6bced 100644 --- a/tests/.config/.cppcheck_suppression_list +++ b/tests/.config/.cppcheck_suppression_list @@ -61,5 +61,5 @@ unusedFunction:../kactl/content/number-theory/ModPow.h:13 unusedFunction:../kactl/stress-tests/utilities/genTree.h:49 containerOutOfBounds:../library/data_structures_[l,r)/uncommon/permutation_tree.hpp:85 ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/bit.hpp:5 -ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/lazy_seg_tree.hpp:3 +ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/lazy_seg_tree.hpp:4 shiftTooManyBits:../library/math/matrix_related/xor_basis_ordered.hpp:18