Skip to content

Commit 421ea33

Browse files
lrvideckisweb-flow
andauthored
Test (#170)
* Refactor update and query methods in lazy_seg_tree * [auto-verifier] verify commit b791873 * Refactor lazy segment tree methods for clarity * Update persistent.hpp * Rename query_impl to query for clarity * Rename query_impl to query for clarity * [auto-verifier] verify commit b919a22 * format --------- Co-authored-by: GitHub <noreply@github.com>
1 parent 00695a4 commit 421ea33

File tree

6 files changed

+55
-58
lines changed

6 files changed

+55
-58
lines changed

.verify-helper/timestamps.remote.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,39 @@
44
"tests/library_checker_aizu_tests/convolution/min_plus_convolution.test.cpp": "2024-11-17 14:04:03 -0600",
55
"tests/library_checker_aizu_tests/data_structures/binary_search_example.test.cpp": "2024-11-18 10:51:39 -0600",
66
"tests/library_checker_aizu_tests/data_structures/binary_trie.test.cpp": "2026-01-18 02:20:40 +0000",
7-
"tests/library_checker_aizu_tests/data_structures/bit.test.cpp": "2026-01-18 02:20:40 +0000",
7+
"tests/library_checker_aizu_tests/data_structures/bit.test.cpp": "2026-01-18 03:03:57 -0700",
88
"tests/library_checker_aizu_tests/data_structures/bit_inc.test.cpp": "2026-01-18 02:20:40 +0000",
99
"tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp": "2026-01-18 02:20:40 +0000",
1010
"tests/library_checker_aizu_tests/data_structures/bit_rupq.test.cpp": "2026-01-18 02:20:40 +0000",
1111
"tests/library_checker_aizu_tests/data_structures/bit_rurq.test.cpp": "2026-01-18 02:20:40 +0000",
12-
"tests/library_checker_aizu_tests/data_structures/bit_walk.test.cpp": "2026-01-18 02:20:40 +0000",
12+
"tests/library_checker_aizu_tests/data_structures/bit_walk.test.cpp": "2026-01-18 03:03:57 -0700",
1313
"tests/library_checker_aizu_tests/data_structures/deque.test.cpp": "2026-01-18 02:20:40 +0000",
1414
"tests/library_checker_aizu_tests/data_structures/deque_index.test.cpp": "2026-01-18 02:20:40 +0000",
1515
"tests/library_checker_aizu_tests/data_structures/deque_op.test.cpp": "2026-01-18 02:20:40 +0000",
1616
"tests/library_checker_aizu_tests/data_structures/deque_sliding_window.test.cpp": "2026-01-18 02:20:40 +0000",
1717
"tests/library_checker_aizu_tests/data_structures/disjoint_rmq_inc.test.cpp": "2026-01-18 02:20:40 +0000",
1818
"tests/library_checker_aizu_tests/data_structures/disjoint_rmq_inc_lines.test.cpp": "2026-01-18 02:20:40 +0000",
1919
"tests/library_checker_aizu_tests/data_structures/disjoint_rmq_inc_sum.test.cpp": "2026-01-18 02:20:40 +0000",
20-
"tests/library_checker_aizu_tests/data_structures/distinct_query.test.cpp": "2026-01-18 02:20:40 +0000",
20+
"tests/library_checker_aizu_tests/data_structures/distinct_query.test.cpp": "2026-01-18 03:05:20 -0700",
2121
"tests/library_checker_aizu_tests/data_structures/dsu.test.cpp": "2026-01-18 02:20:40 +0000",
2222
"tests/library_checker_aizu_tests/data_structures/dsu_bipartite.test.cpp": "2026-01-18 02:20:40 +0000",
2323
"tests/library_checker_aizu_tests/data_structures/dsu_restorable.test.cpp": "2026-01-18 02:20:40 +0000",
24-
"tests/library_checker_aizu_tests/data_structures/dsu_segtree_undo_trick.test.cpp": "2026-01-18 02:20:40 +0000",
24+
"tests/library_checker_aizu_tests/data_structures/dsu_segtree_undo_trick.test.cpp": "2026-01-18 03:03:57 -0700",
2525
"tests/library_checker_aizu_tests/data_structures/implicit_seg_tree.test.cpp": "2026-01-18 02:20:40 +0000",
2626
"tests/library_checker_aizu_tests/data_structures/kruskal_tree_aizu.test.cpp": "2026-01-18 02:20:40 +0000",
27-
"tests/library_checker_aizu_tests/data_structures/kth_smallest_pst.test.cpp": "2026-01-18 02:20:40 +0000",
27+
"tests/library_checker_aizu_tests/data_structures/kth_smallest_pst.test.cpp": "2026-01-18 03:06:14 -0700",
2828
"tests/library_checker_aizu_tests/data_structures/kth_smallest_wavelet_matrix.test.cpp": "2026-01-18 02:20:40 +0000",
29-
"tests/library_checker_aizu_tests/data_structures/lazy_segment_tree.test.cpp": "2026-01-18 02:20:40 +0000",
30-
"tests/library_checker_aizu_tests/data_structures/lazy_segment_tree_constructor.test.cpp": "2026-01-18 02:20:40 +0000",
31-
"tests/library_checker_aizu_tests/data_structures/lazy_segment_tree_inc.test.cpp": "2026-01-18 02:20:40 +0000",
32-
"tests/library_checker_aizu_tests/data_structures/lazy_segment_tree_inc_constructor.test.cpp": "2026-01-18 02:20:40 +0000",
29+
"tests/library_checker_aizu_tests/data_structures/lazy_segment_tree.test.cpp": "2026-01-18 03:03:57 -0700",
30+
"tests/library_checker_aizu_tests/data_structures/lazy_segment_tree_constructor.test.cpp": "2026-01-18 03:03:57 -0700",
31+
"tests/library_checker_aizu_tests/data_structures/lazy_segment_tree_inc.test.cpp": "2026-01-18 02:59:09 -0700",
32+
"tests/library_checker_aizu_tests/data_structures/lazy_segment_tree_inc_constructor.test.cpp": "2026-01-18 02:59:09 -0700",
3333
"tests/library_checker_aizu_tests/data_structures/line_tree_aizu.test.cpp": "2026-01-18 02:20:40 +0000",
3434
"tests/library_checker_aizu_tests/data_structures/line_tree_lib_checker.test.cpp": "2026-01-18 02:20:40 +0000",
35-
"tests/library_checker_aizu_tests/data_structures/merge_sort_tree.test.cpp": "2026-01-18 02:20:40 +0000",
35+
"tests/library_checker_aizu_tests/data_structures/merge_sort_tree.test.cpp": "2026-01-18 03:06:56 -0700",
3636
"tests/library_checker_aizu_tests/data_structures/mode_query.test.cpp": "2026-01-18 02:20:40 +0000",
3737
"tests/library_checker_aizu_tests/data_structures/permutation_tree.test.cpp": "2026-01-18 02:20:40 +0000",
38-
"tests/library_checker_aizu_tests/data_structures/persistent_queue_tree.test.cpp": "2026-01-18 02:20:40 +0000",
39-
"tests/library_checker_aizu_tests/data_structures/persistent_seg_tree.test.cpp": "2026-01-18 02:20:40 +0000",
38+
"tests/library_checker_aizu_tests/data_structures/persistent_queue_tree.test.cpp": "2026-01-18 03:05:20 -0700",
39+
"tests/library_checker_aizu_tests/data_structures/persistent_seg_tree.test.cpp": "2026-01-18 03:05:20 -0700",
4040
"tests/library_checker_aizu_tests/data_structures/pq_ds_undo_sliding_window.test.cpp": "2026-01-18 02:20:40 +0000",
4141
"tests/library_checker_aizu_tests/data_structures/pq_ds_undo_with_dsu.test.cpp": "2026-01-18 02:20:40 +0000",
4242
"tests/library_checker_aizu_tests/data_structures/range_parallel_dsu.test.cpp": "2026-01-18 02:20:40 +0000",
@@ -75,15 +75,15 @@
7575
"tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp": "2025-08-06 16:18:37 -0600",
7676
"tests/library_checker_aizu_tests/handmade_tests/hilbert_mos.test.cpp": "2026-01-18 02:20:40 +0000",
7777
"tests/library_checker_aizu_tests/handmade_tests/manacher.test.cpp": "2026-01-18 02:20:40 +0000",
78-
"tests/library_checker_aizu_tests/handmade_tests/merge_st_and_wavelet.test.cpp": "2026-01-18 02:20:40 +0000",
78+
"tests/library_checker_aizu_tests/handmade_tests/merge_st_and_wavelet.test.cpp": "2026-01-18 03:06:56 -0700",
7979
"tests/library_checker_aizu_tests/handmade_tests/mobius.test.cpp": "2025-02-10 14:50:36 -0700",
8080
"tests/library_checker_aizu_tests/handmade_tests/mod_division.test.cpp": "2025-09-07 16:12:35 -0600",
8181
"tests/library_checker_aizu_tests/handmade_tests/n_choose_k.test.cpp": "2025-08-28 13:19:16 -0600",
8282
"tests/library_checker_aizu_tests/handmade_tests/permutation_tree_small.test.cpp": "2026-01-18 02:20:40 +0000",
8383
"tests/library_checker_aizu_tests/handmade_tests/rmq_small_n.test.cpp": "2026-01-18 02:20:40 +0000",
8484
"tests/library_checker_aizu_tests/handmade_tests/sa_find_subarray.test.cpp": "2026-01-18 02:20:40 +0000",
85-
"tests/library_checker_aizu_tests/handmade_tests/seg_tree_find.test.cpp": "2026-01-18 02:20:40 +0000",
86-
"tests/library_checker_aizu_tests/handmade_tests/seg_tree_find_small.test.cpp": "2026-01-18 02:20:40 +0000",
85+
"tests/library_checker_aizu_tests/handmade_tests/seg_tree_find.test.cpp": "2026-01-18 03:03:57 -0700",
86+
"tests/library_checker_aizu_tests/handmade_tests/seg_tree_find_small.test.cpp": "2026-01-18 03:03:57 -0700",
8787
"tests/library_checker_aizu_tests/loops/chooses.test.cpp": "2025-02-10 14:50:36 -0700",
8888
"tests/library_checker_aizu_tests/loops/quotients.test.cpp": "2024-11-17 14:04:03 -0600",
8989
"tests/library_checker_aizu_tests/loops/submasks.test.cpp": "2025-02-10 14:50:36 -0700",
@@ -112,7 +112,7 @@
112112
"tests/library_checker_aizu_tests/strings/lcp_query_zfunc.test.cpp": "2026-01-18 02:20:40 +0000",
113113
"tests/library_checker_aizu_tests/strings/lcs_dp.test.cpp": "2025-08-05 19:19:23 -0600",
114114
"tests/library_checker_aizu_tests/strings/lcs_queries.test.cpp": "2026-01-18 02:20:40 +0000",
115-
"tests/library_checker_aizu_tests/strings/lcs_queries_merge_sort_tree.test.cpp": "2026-01-18 02:20:40 +0000",
115+
"tests/library_checker_aizu_tests/strings/lcs_queries_merge_sort_tree.test.cpp": "2026-01-18 03:06:56 -0700",
116116
"tests/library_checker_aizu_tests/strings/manacher.test.cpp": "2025-08-05 19:19:23 -0600",
117117
"tests/library_checker_aizu_tests/strings/multi_matching_bs.test.cpp": "2026-01-18 02:20:40 +0000",
118118
"tests/library_checker_aizu_tests/strings/prefix_function.test.cpp": "2025-08-05 19:19:23 -0600",
@@ -129,7 +129,7 @@
129129
"tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp": "2025-12-11 21:47:53 +0000",
130130
"tests/library_checker_aizu_tests/trees/edge_cd_reroot_dp.test.cpp": "2025-09-07 15:50:55 -0600",
131131
"tests/library_checker_aizu_tests/trees/hld_aizu1.test.cpp": "2026-01-18 02:20:40 +0000",
132-
"tests/library_checker_aizu_tests/trees/hld_aizu2.test.cpp": "2026-01-18 02:20:40 +0000",
132+
"tests/library_checker_aizu_tests/trees/hld_aizu2.test.cpp": "2026-01-18 03:03:57 -0700",
133133
"tests/library_checker_aizu_tests/trees/hld_lib_checker_path.test.cpp": "2026-01-18 02:20:40 +0000",
134134
"tests/library_checker_aizu_tests/trees/hld_lib_checker_subtree_edges.test.cpp": "2026-01-18 02:20:40 +0000",
135135
"tests/library_checker_aizu_tests/trees/hld_lib_checker_subtree_nodes.test.cpp": "2026-01-18 02:20:40 +0000",

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,29 @@ struct seg_tree {
2323
}
2424
}
2525
void update(int l, int r, ll change) { // [l, r)
26-
update_impl(l, r, change, 0, n, 1);
26+
update(l, r, change, 0, n, 1);
2727
}
28-
void update_impl(int l, int r, ll change, int tl, int tr,
28+
void update(int l, int r, ll change, int tl, int tr,
2929
int v) {
3030
if (r <= tl || tr <= l) return;
3131
if (l <= tl && tr <= r)
3232
return apply(change, tl, tr, v);
3333
int tm = split(tl, tr);
3434
push(tl, tm, tr, v);
35-
update_impl(l, r, change, tl, tm, 2 * v);
36-
update_impl(l, r, change, tm, tr, 2 * v + 1);
35+
update(l, r, change, tl, tm, 2 * v);
36+
update(l, r, change, tm, tr, 2 * v + 1);
3737
tree[v] = op(tree[2 * v], tree[2 * v + 1]);
3838
}
3939
ll query(int l, int r) { // [l, r)
40-
return query_impl(l, r, 0, n, 1);
40+
return query(l, r, 0, n, 1);
4141
}
42-
ll query_impl(int l, int r, int tl, int tr, int v) {
42+
ll query(int l, int r, int tl, int tr, int v) {
4343
if (r <= tl || tr <= l) return 0;
4444
if (l <= tl && tr <= r) return tree[v];
4545
int tm = split(tl, tr);
4646
push(tl, tm, tr, v);
47-
return op(query_impl(l, r, tl, tm, 2 * v),
48-
query_impl(l, r, tm, tr, 2 * v + 1));
47+
return op(query(l, r, tl, tm, 2 * v),
48+
query(l, r, tm, tr, 2 * v + 1));
4949
}
5050
#include "seg_tree_uncommon/find_first.hpp"
5151
#include "seg_tree_uncommon/find_last.hpp"

library/data_structures_[l,r)/seg_tree_uncommon/kth_smallest_query.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ struct kth_smallest {
2020
//! @space O(log(maxv - minv)) for recursion stack; no
2121
//! new nodes are allocated
2222
int query(int l, int r, int k) {
23-
return query_impl(k, pst.root_l, pst.root_r,
24-
pst.roots[l], pst.roots[r]);
23+
return query(k, pst.root_l, pst.root_r, pst.roots[l],
24+
pst.roots[r]);
2525
}
26-
int query_impl(int k, int tl, int tr, int vl, int vr) {
26+
int query(int k, int tl, int tr, int vl, int vr) {
2727
if (tr - tl == 1) return tl;
2828
int tm = tl + (tr - tl) / 2;
2929
int left_count = pst.tree[pst.tree[vr].lch].sum -
3030
pst.tree[pst.tree[vl].lch].sum;
3131
if (left_count >= k)
32-
return query_impl(k, tl, tm, pst.tree[vl].lch,
32+
return query(k, tl, tm, pst.tree[vl].lch,
3333
pst.tree[vr].lch);
34-
return query_impl(k - left_count, tm, tr,
35-
pst.tree[vl].rch, pst.tree[vr].rch);
34+
return query(k - left_count, tm, tr, pst.tree[vl].rch,
35+
pst.tree[vr].rch);
3636
}
3737
};

library/data_structures_[l,r)/seg_tree_uncommon/merge_sort_tree.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ struct merge_sort_tree {
1414
//! @time O(log(n)^2)
1515
//! @space O(1)
1616
int query(int l, int r, int vl, int vr) {
17-
return query_impl(l, r, vl, vr, 0, n, 1);
17+
return query(l, r, vl, vr, 0, n, 1);
1818
}
19-
int query_impl(int l, int r, int vl, int vr, int tl,
20-
int tr, int v) {
19+
int query(int l, int r, int vl, int vr, int tl, int tr,
20+
int v) {
2121
if (r <= tl || tr <= l) return 0;
2222
if (l <= tl && tr <= r)
2323
return ranges::lower_bound(tree[v], vr) -
2424
ranges::lower_bound(tree[v], vl);
2525
int tm = split(tl, tr);
26-
return query_impl(l, r, vl, vr, tl, tm, 2 * v) +
27-
query_impl(l, r, vl, vr, tm, tr, 2 * v + 1);
26+
return query(l, r, vl, vr, tl, tm, 2 * v) +
27+
query(l, r, vl, vr, tm, tr, 2 * v + 1);
2828
}
2929
};

library/data_structures_[l,r)/seg_tree_uncommon/persistent.hpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,31 @@ struct PST {
2222
root_l(root_l), root_r(root_r), roots(1),
2323
tree(1, {0LL, 0, 0}) {}
2424
void update(int idx, ll change, int version) {
25-
roots.push_back(update_impl(idx, change, root_l,
26-
root_r, roots[version]));
25+
roots.push_back(
26+
update(idx, change, root_l, root_r, roots[version]));
2727
}
28-
int update_impl(int idx, ll change, int tl, int tr,
29-
int v) {
28+
int update(int idx, ll change, int tl, int tr, int v) {
3029
if (tr - tl == 1) {
3130
tree.emplace_back(tree[v].sum + change, 0, 0);
3231
return sz(tree) - 1;
3332
}
3433
int tm = tl + (tr - tl) / 2;
3534
int lch = tree[v].lch;
3635
int rch = tree[v].rch;
37-
if (idx < tm)
38-
lch = update_impl(idx, change, tl, tm, lch);
39-
else rch = update_impl(idx, change, tm, tr, rch);
36+
if (idx < tm) lch = update(idx, change, tl, tm, lch);
37+
else rch = update(idx, change, tm, tr, rch);
4038
tree.emplace_back(tree[lch].sum + tree[rch].sum, lch,
4139
rch);
4240
return sz(tree) - 1;
4341
}
4442
ll query(int l, int r, int version) { // [l, r)
45-
return query_impl(l, r, root_l, root_r,
46-
roots[version]);
43+
return query(l, r, root_l, root_r, roots[version]);
4744
}
48-
ll query_impl(int l, int r, int tl, int tr, int v) {
45+
ll query(int l, int r, int tl, int tr, int v) {
4946
if (v == 0 || r <= tl || tr <= l) return 0;
5047
if (l <= tl && tr <= r) return tree[v].sum;
5148
int tm = tl + (tr - tl) / 2;
52-
return query_impl(l, r, tl, tm, tree[v].lch) +
53-
query_impl(l, r, tm, tr, tree[v].rch);
49+
return query(l, r, tl, tm, tree[v].lch) +
50+
query(l, r, tm, tr, tree[v].rch);
5451
}
5552
};

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,29 @@ struct seg_tree {
2222
lazy[v] = 0;
2323
}
2424
}
25-
void update(int l, int r, ll change) { // [l, r]
26-
update_impl(l, r, change, 0, n - 1, 1);
25+
void update(int l, int r, ll change) {
26+
update(l, r, change, 0, n - 1, 1);
2727
}
28-
void update_impl(int l, int r, ll change, int tl, int tr,
28+
void update(int l, int r, ll change, int tl, int tr,
2929
int v) {
3030
if (r < tl || tr < l) return;
3131
if (l <= tl && tr <= r)
3232
return apply(change, tl, tr, v);
3333
int tm = split(tl, tr);
3434
push(tl, tm, tr, v);
35-
update_impl(l, r, change, tl, tm, 2 * v);
36-
update_impl(l, r, change, tm + 1, tr, 2 * v + 1);
35+
update(l, r, change, tl, tm, 2 * v);
36+
update(l, r, change, tm + 1, tr, 2 * v + 1);
3737
tree[v] = op(tree[2 * v], tree[2 * v + 1]);
3838
}
39-
ll query(int l, int r) { // [l, r]
40-
return query_impl(l, r, 0, n - 1, 1);
39+
ll query(int l, int r) {
40+
return query(l, r, 0, n - 1, 1);
4141
}
42-
ll query_impl(int l, int r, int tl, int tr, int v) {
42+
ll query(int l, int r, int tl, int tr, int v) {
4343
if (r < tl || tr < l) return 0;
4444
if (l <= tl && tr <= r) return tree[v];
4545
int tm = split(tl, tr);
4646
push(tl, tm, tr, v);
47-
return op(query_impl(l, r, tl, tm, 2 * v),
48-
query_impl(l, r, tm + 1, tr, 2 * v + 1));
47+
return op(query(l, r, tl, tm, 2 * v),
48+
query(l, r, tm + 1, tr, 2 * v + 1));
4949
}
5050
};

0 commit comments

Comments
 (0)