Skip to content

Commit 5e7a4c1

Browse files
author
Cameron Custer
committed
Merge remote-tracking branch 'origin/dev' into cpp20
# Conflicts: # .verify-helper/timestamps.remote.json # library/data_structures_[l,r)/uncommon/priority_queue_of_updates.hpp
2 parents 5062d4f + 4387d6f commit 5e7a4c1

38 files changed

Lines changed: 150 additions & 151 deletions

.verify-helper/timestamps.remote.json

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"tests/library_checker_aizu_tests/convolution/gcd_convolution.test.cpp": "2025-08-28 13:19:16 -0600",
33
"tests/library_checker_aizu_tests/convolution/lcm_convolution.test.cpp": "2025-08-28 13:19:16 -0600",
4-
"tests/library_checker_aizu_tests/convolution/min_plus_convolution.test.cpp": "2026-04-12 16:21:27 -0600",
4+
"tests/library_checker_aizu_tests/convolution/min_plus_convolution.test.cpp": "2026-07-06 09:57:36 -0700",
55
"tests/library_checker_aizu_tests/convolution/xor_convolution.test.cpp": "2026-03-06 12:17:28 -0700",
66
"tests/library_checker_aizu_tests/data_structures/binary_search_example.test.cpp": "2024-11-18 10:51:39 -0600",
77
"tests/library_checker_aizu_tests/data_structures/binary_trie.test.cpp": "2026-01-18 02:20:40 +0000",
8-
"tests/library_checker_aizu_tests/data_structures/bit.test.cpp": "2026-04-26 11:38:07 -0600",
9-
"tests/library_checker_aizu_tests/data_structures/bit_inc.test.cpp": "2026-04-06 12:17:32 -0600",
10-
"tests/library_checker_aizu_tests/data_structures/bit_inc_walk.test.cpp": "2026-04-06 12:17:32 -0600",
11-
"tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp": "2026-04-06 12:17:32 -0600",
12-
"tests/library_checker_aizu_tests/data_structures/bit_rupq.test.cpp": "2026-04-06 12:17:32 -0600",
13-
"tests/library_checker_aizu_tests/data_structures/bit_rurq.test.cpp": "2026-04-06 12:17:32 -0600",
14-
"tests/library_checker_aizu_tests/data_structures/bit_walk.test.cpp": "2026-04-26 11:38:07 -0600",
8+
"tests/library_checker_aizu_tests/data_structures/bit.test.cpp": "2026-07-06 09:26:00 -0700",
9+
"tests/library_checker_aizu_tests/data_structures/bit_inc.test.cpp": "2026-07-06 09:26:00 -0700",
10+
"tests/library_checker_aizu_tests/data_structures/bit_inc_walk.test.cpp": "2026-07-06 09:26:00 -0700",
11+
"tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp": "2026-07-06 09:26:00 -0700",
12+
"tests/library_checker_aizu_tests/data_structures/bit_rupq.test.cpp": "2026-07-06 09:26:00 -0700",
13+
"tests/library_checker_aizu_tests/data_structures/bit_rurq.test.cpp": "2026-07-06 09:26:00 -0700",
14+
"tests/library_checker_aizu_tests/data_structures/bit_walk.test.cpp": "2026-07-06 09:26:00 -0700",
1515
"tests/library_checker_aizu_tests/data_structures/deque.test.cpp": "2026-07-06 10:14:01 -0700",
1616
"tests/library_checker_aizu_tests/data_structures/deque_index.test.cpp": "2026-07-06 10:14:01 -0700",
1717
"tests/library_checker_aizu_tests/data_structures/deque_op.test.cpp": "2026-07-06 10:14:01 -0700",
@@ -55,33 +55,33 @@
5555
"tests/library_checker_aizu_tests/dsu/range_parallel_dsu.test.cpp": "2026-04-26 11:38:07 -0600",
5656
"tests/library_checker_aizu_tests/flow/hungarian.test.cpp": "2024-11-17 14:04:03 -0600",
5757
"tests/library_checker_aizu_tests/flow/min_cost_max_flow.test.cpp": "2026-04-06 14:41:55 -0600",
58-
"tests/library_checker_aizu_tests/graphs/bcc_callback_aizu_bcc.test.cpp": "2026-04-12 16:21:27 -0600",
59-
"tests/library_checker_aizu_tests/graphs/bcc_callback_aizu_two_edge_cc.test.cpp": "2026-04-12 16:21:27 -0600",
60-
"tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_bcc.test.cpp": "2026-04-12 16:21:27 -0600",
61-
"tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_two_cc.test.cpp": "2026-04-12 16:21:27 -0600",
62-
"tests/library_checker_aizu_tests/graphs/biconnected_components.test.cpp": "2026-04-26 11:38:07 -0600",
58+
"tests/library_checker_aizu_tests/graphs/bcc_callback_aizu_bcc.test.cpp": "2026-07-06 09:57:36 -0700",
59+
"tests/library_checker_aizu_tests/graphs/bcc_callback_aizu_two_edge_cc.test.cpp": "2026-07-06 09:57:36 -0700",
60+
"tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_bcc.test.cpp": "2026-07-06 09:57:36 -0700",
61+
"tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_two_cc.test.cpp": "2026-07-06 09:57:36 -0700",
62+
"tests/library_checker_aizu_tests/graphs/biconnected_components.test.cpp": "2026-07-06 09:57:36 -0700",
6363
"tests/library_checker_aizu_tests/graphs/connected_components_of_complement_graph.test.cpp": "2026-04-06 14:41:55 -0600",
6464
"tests/library_checker_aizu_tests/graphs/dijkstra_aizu.test.cpp": "2026-04-06 14:41:55 -0600",
6565
"tests/library_checker_aizu_tests/graphs/dijkstra_lib_checker.test.cpp": "2026-04-26 11:38:07 -0600",
66-
"tests/library_checker_aizu_tests/graphs/directed_cycle.test.cpp": "2026-04-12 16:21:27 -0600",
66+
"tests/library_checker_aizu_tests/graphs/directed_cycle.test.cpp": "2026-07-06 09:57:36 -0700",
6767
"tests/library_checker_aizu_tests/graphs/enumerate_triangles.test.cpp": "2026-04-26 11:38:07 -0600",
68-
"tests/library_checker_aizu_tests/graphs/euler_walk_directed.test.cpp": "2026-04-12 16:21:27 -0600",
69-
"tests/library_checker_aizu_tests/graphs/euler_walk_undirected.test.cpp": "2026-04-12 16:21:27 -0600",
68+
"tests/library_checker_aizu_tests/graphs/euler_walk_directed.test.cpp": "2026-07-06 09:57:36 -0700",
69+
"tests/library_checker_aizu_tests/graphs/euler_walk_undirected.test.cpp": "2026-07-06 09:57:36 -0700",
7070
"tests/library_checker_aizu_tests/graphs/hopcroft_karp_aizu.test.cpp": "2026-05-01 11:34:51 -0600",
7171
"tests/library_checker_aizu_tests/graphs/hopcroft_karp_lib_checker.test.cpp": "2026-05-01 11:34:51 -0600",
7272
"tests/library_checker_aizu_tests/graphs/mst.test.cpp": "2026-07-06 09:32:13 -0700",
73-
"tests/library_checker_aizu_tests/graphs/offline_incremental_scc.test.cpp": "2026-04-12 16:21:27 -0600",
74-
"tests/library_checker_aizu_tests/graphs/strongly_connected_components_aizu.test.cpp": "2026-04-12 16:21:27 -0600",
75-
"tests/library_checker_aizu_tests/graphs/strongly_connected_components_lib_checker.test.cpp": "2026-04-12 16:21:27 -0600",
76-
"tests/library_checker_aizu_tests/graphs/two_edge_components.test.cpp": "2026-04-12 16:21:27 -0600",
73+
"tests/library_checker_aizu_tests/graphs/offline_incremental_scc.test.cpp": "2026-07-06 09:57:36 -0700",
74+
"tests/library_checker_aizu_tests/graphs/strongly_connected_components_aizu.test.cpp": "2026-07-06 09:57:36 -0700",
75+
"tests/library_checker_aizu_tests/graphs/strongly_connected_components_lib_checker.test.cpp": "2026-07-06 09:57:36 -0700",
76+
"tests/library_checker_aizu_tests/graphs/two_edge_components.test.cpp": "2026-07-06 09:57:36 -0700",
7777
"tests/library_checker_aizu_tests/handmade_tests/count_paths.test.cpp": "2026-07-06 10:14:01 -0700",
7878
"tests/library_checker_aizu_tests/handmade_tests/dsu.test.cpp": "2026-01-22 10:08:22 -0700",
79-
"tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp": "2026-04-27 08:17:20 -0600",
79+
"tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp": "2026-07-06 09:57:36 -0700",
8080
"tests/library_checker_aizu_tests/handmade_tests/fib_matrix_expo.test.cpp": "2026-01-28 21:48:16 -0700",
8181
"tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp": "2026-04-26 11:38:07 -0600",
8282
"tests/library_checker_aizu_tests/handmade_tests/hilbert_mos.test.cpp": "2026-01-18 02:20:40 +0000",
8383
"tests/library_checker_aizu_tests/handmade_tests/kd_bit.test.cpp": "2026-02-19 18:06:52 -0700",
84-
"tests/library_checker_aizu_tests/handmade_tests/kth_par.test.cpp": "2026-06-27 18:29:52 -0500",
84+
"tests/library_checker_aizu_tests/handmade_tests/kth_par.test.cpp": "2026-07-06 09:57:36 -0700",
8585
"tests/library_checker_aizu_tests/handmade_tests/manacher.test.cpp": "2026-04-26 11:38:07 -0600",
8686
"tests/library_checker_aizu_tests/handmade_tests/merge_st_and_wavelet.test.cpp": "2026-04-26 11:38:07 -0600",
8787
"tests/library_checker_aizu_tests/handmade_tests/mobius.test.cpp": "2025-02-10 14:50:36 -0700",
@@ -90,7 +90,7 @@
9090
"tests/library_checker_aizu_tests/handmade_tests/permutation_tree_small.test.cpp": "2026-05-24 23:00:07 -0500",
9191
"tests/library_checker_aizu_tests/handmade_tests/rmq_small_n.test.cpp": "2026-05-24 23:00:07 -0500",
9292
"tests/library_checker_aizu_tests/handmade_tests/sa_find_subarray.test.cpp": "2026-07-06 09:32:13 -0700",
93-
"tests/library_checker_aizu_tests/handmade_tests/seg_tree_find.test.cpp": "2026-04-26 11:38:07 -0600",
93+
"tests/library_checker_aizu_tests/handmade_tests/seg_tree_find.test.cpp": "2026-07-06 09:26:00 -0700",
9494
"tests/library_checker_aizu_tests/handmade_tests/seg_tree_find_small.test.cpp": "2026-04-26 11:38:07 -0600",
9595
"tests/library_checker_aizu_tests/handmade_tests/seg_tree_midpoint.test.cpp": "2026-04-26 11:38:07 -0600",
9696
"tests/library_checker_aizu_tests/handmade_tests/xor_basis_walk.test.cpp": "2026-03-08 15:33:28 -0600",
@@ -108,7 +108,7 @@
108108
"tests/library_checker_aizu_tests/math/partitions.test.cpp": "2025-08-28 13:19:16 -0600",
109109
"tests/library_checker_aizu_tests/math/prime_sieve.test.cpp": "2024-11-22 11:54:52 -0600",
110110
"tests/library_checker_aizu_tests/math/solve_linear_mod.test.cpp": "2026-07-06 10:14:01 -0700",
111-
"tests/library_checker_aizu_tests/math/tetration.test.cpp": "2024-11-17 14:04:03 -0600",
111+
"tests/library_checker_aizu_tests/math/tetration.test.cpp": "2026-07-06 09:26:00 -0700",
112112
"tests/library_checker_aizu_tests/math/totient.test.cpp": "2024-11-17 14:04:03 -0600",
113113
"tests/library_checker_aizu_tests/math/xor_basis_intersection.test.cpp": "2026-04-26 11:38:07 -0600",
114114
"tests/library_checker_aizu_tests/monotonic_stack_related/cartesian_binary_tree.test.cpp": "2026-04-06 13:24:49 -0600",
@@ -120,7 +120,7 @@
120120
"tests/library_checker_aizu_tests/strings/lcp_query_palindrome.test.cpp": "2026-07-06 09:32:13 -0700",
121121
"tests/library_checker_aizu_tests/strings/lcp_query_zfunc.test.cpp": "2026-07-06 09:32:13 -0700",
122122
"tests/library_checker_aizu_tests/strings/lcs_dp.test.cpp": "2025-08-05 19:19:23 -0600",
123-
"tests/library_checker_aizu_tests/strings/lcs_queries.test.cpp": "2026-04-06 12:17:32 -0600",
123+
"tests/library_checker_aizu_tests/strings/lcs_queries.test.cpp": "2026-07-06 09:26:00 -0700",
124124
"tests/library_checker_aizu_tests/strings/lcs_queries_merge_sort_tree.test.cpp": "2026-04-26 11:38:07 -0600",
125125
"tests/library_checker_aizu_tests/strings/manacher.test.cpp": "2026-04-26 11:38:07 -0600",
126126
"tests/library_checker_aizu_tests/strings/multi_matching_bs.test.cpp": "2026-07-06 09:32:13 -0700",
@@ -132,23 +132,23 @@
132132
"tests/library_checker_aizu_tests/strings/suffix_array_short.test.cpp": "2026-04-12 06:15:25 -0600",
133133
"tests/library_checker_aizu_tests/strings/trie.test.cpp": "2026-01-17 12:38:18 -0700",
134134
"tests/library_checker_aizu_tests/strings/wildcard_pattern_matching.test.cpp": "2026-07-06 09:32:13 -0700",
135-
"tests/library_checker_aizu_tests/trees/cd_count_paths_per_length.test.cpp": "2026-04-26 21:56:36 -0600",
136-
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp": "2026-04-27 08:17:20 -0600",
137-
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_update.test.cpp": "2026-04-27 08:17:20 -0600",
138-
"tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp": "2026-04-27 08:17:20 -0600",
139-
"tests/library_checker_aizu_tests/trees/edge_cd_reroot_dp.test.cpp": "2026-04-27 08:17:20 -0600",
140-
"tests/library_checker_aizu_tests/trees/hld_aizu1.test.cpp": "2026-04-12 16:21:27 -0600",
135+
"tests/library_checker_aizu_tests/trees/cd_count_paths_per_length.test.cpp": "2026-07-06 09:57:36 -0700",
136+
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp": "2026-07-06 09:57:36 -0700",
137+
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_update.test.cpp": "2026-07-06 09:57:36 -0700",
138+
"tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp": "2026-07-06 09:57:36 -0700",
139+
"tests/library_checker_aizu_tests/trees/edge_cd_reroot_dp.test.cpp": "2026-07-06 09:57:36 -0700",
140+
"tests/library_checker_aizu_tests/trees/hld_aizu1.test.cpp": "2026-07-06 09:26:00 -0700",
141141
"tests/library_checker_aizu_tests/trees/hld_aizu2.test.cpp": "2026-04-26 11:38:07 -0600",
142-
"tests/library_checker_aizu_tests/trees/hld_lib_checker_path.test.cpp": "2026-04-12 16:21:27 -0600",
143-
"tests/library_checker_aizu_tests/trees/hld_lib_checker_subtree_edges.test.cpp": "2026-04-12 16:21:27 -0600",
144-
"tests/library_checker_aizu_tests/trees/hld_lib_checker_subtree_nodes.test.cpp": "2026-04-12 16:21:27 -0600",
142+
"tests/library_checker_aizu_tests/trees/hld_lib_checker_path.test.cpp": "2026-07-06 09:26:00 -0700",
143+
"tests/library_checker_aizu_tests/trees/hld_lib_checker_subtree_edges.test.cpp": "2026-07-06 09:26:00 -0700",
144+
"tests/library_checker_aizu_tests/trees/hld_lib_checker_subtree_nodes.test.cpp": "2026-07-06 09:26:00 -0700",
145145
"tests/library_checker_aizu_tests/trees/kth_path_hagerup.test.cpp": "2026-07-06 10:14:01 -0700",
146-
"tests/library_checker_aizu_tests/trees/kth_path_ladder.test.cpp": "2026-06-27 13:02:40 -0500",
147-
"tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp": "2026-06-27 18:29:52 -0500",
146+
"tests/library_checker_aizu_tests/trees/kth_path_ladder.test.cpp": "2026-07-06 09:57:36 -0700",
147+
"tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp": "2026-07-06 09:57:36 -0700",
148148
"tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp": "2026-07-06 10:14:01 -0700",
149149
"tests/library_checker_aizu_tests/trees/lca_all_methods_aizu.test.cpp": "2026-07-06 10:14:01 -0700",
150150
"tests/library_checker_aizu_tests/trees/lca_all_methods_lib_checker.test.cpp": "2026-07-06 10:14:01 -0700",
151-
"tests/library_checker_aizu_tests/trees/shallowest_aizu_tree_height.test.cpp": "2026-04-12 16:21:27 -0600",
152-
"tests/library_checker_aizu_tests/trees/shallowest_lib_checker_tree_path_composite.test.cpp": "2026-04-26 11:38:07 -0600",
153-
"tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp": "2026-04-12 16:21:27 -0600"
154-
}
151+
"tests/library_checker_aizu_tests/trees/shallowest_aizu_tree_height.test.cpp": "2026-07-06 09:57:36 -0700",
152+
"tests/library_checker_aizu_tests/trees/shallowest_lib_checker_tree_path_composite.test.cpp": "2026-07-06 09:57:36 -0700",
153+
"tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp": "2026-07-06 09:57:36 -0700"
154+
}

library/contest/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ freopen("output.txt", "w", stdout);
99
If you changed something for debugging, add a `cout << "don't submit" << endl;`
1010
or `assert(0);` at the end of the code
1111

12-
for policy base DS:
12+
for policy-based DS:
1313
```
1414
#include <bits/extc++.h>
1515
```
@@ -25,7 +25,7 @@ don't use cin for doubles/floats, it's slow, read into string, then convert to d
2525
cin.exceptions(cin.failbit);
2626
```
2727

28-
- use pramgas for C++ speed boost
28+
- use pragmas for C++ speed boost
2929
```
3030
#pragma GCC optimize("O3,unroll-loops")
3131
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

library/convolution/min_plus_convolution_convex_and_arbitrary.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ vi min_plus(const vi& convex, const vi& arbitrary) {
99
int n = sz(convex);
1010
int m = sz(arbitrary);
1111
vi res(n + m - 1, INT_MAX);
12-
auto dnc = [&](auto dnc, int res_le, int res_ri,
12+
auto dnc = [&](auto&& dnc, int res_le, int res_ri,
1313
int arb_le, int arb_ri) {
1414
if (res_le >= res_ri) return;
1515
int mid_res = (res_le + res_ri) / 2;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! int r = bit.walk2(sum);
88
//! // Returns min r s.t. sum of [0,r] >= sum
99
//! // Returns n if sum of [0,n-1] < sum
10+
//! // Returns -1 if sum <= 0
1011
//! @endcode
1112
//! @time O(n + q log n)
1213
//! @space O(n)
@@ -19,9 +20,9 @@ struct BIT {
1920
for (; i < sz(s); i |= i + 1) s[i] += d;
2021
}
2122
ll query(int r) {
22-
ll ret = 0;
23-
for (; r > 0; r &= r - 1) ret += s[r - 1];
24-
return ret;
23+
ll res = 0;
24+
for (; r > 0; r &= r - 1) res += s[r - 1];
25+
return res;
2526
}
2627
ll query(int l, int r) { return query(r) - query(l); }
2728
#include "bit_uncommon/walk_lambda.hpp"

library/data_structures_[l,r)/bit_uncommon/kd_bit.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ template<int K> struct KD_BIT {
1919
for (; i < sz(s); i |= i + 1) s[i].update(a...);
2020
}
2121
ll query(int l, int r, auto... a) {
22-
ll ans = 0;
23-
for (; l < r; r &= r - 1) ans += s[r - 1].query(a...);
24-
for (; r < l; l &= l - 1) ans -= s[l - 1].query(a...);
25-
return ans;
22+
ll res = 0;
23+
for (; l < r; r &= r - 1) res += s[r - 1].query(a...);
24+
for (; r < l; l &= l - 1) res -= s[l - 1].query(a...);
25+
return res;
2626
}
2727
};
2828
template<> struct KD_BIT<0> {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ struct kth_smallest {
2626
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;
29-
int left_count = pst.tree[pst.tree[vr].lch].sum -
30-
pst.tree[pst.tree[vl].lch].sum;
31-
if (left_count >= k)
29+
int cnt_l = pst.tree[pst.tree[vr].lch].sum -
30+
pst.tree[pst.tree[vl].lch].sum;
31+
if (cnt_l >= k)
3232
return query(k, tl, tm, pst.tree[vl].lch,
3333
pst.tree[vr].lch);
34-
return query(k - left_count, tm, tr, pst.tree[vl].rch,
34+
return query(k - cnt_l, tm, tr, pst.tree[vl].rch,
3535
pst.tree[vr].rch);
3636
}
3737
};

library/data_structures_[l,r)/uncommon/deque_op.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ template<class T, class F> struct deq {
2424
T front() { return (empty(l) ? r[0] : l.back())[0]; }
2525
T back() { return (empty(r) ? l[0] : r.back())[0]; }
2626
int siz() { return sz(l) + sz(r); }
27-
void push_back(T elem) {
27+
void push_back(T val) {
2828
r.push_back(
29-
{elem, empty(r) ? elem : op(r.back()[1], elem)});
29+
{val, empty(r) ? val : op(r.back()[1], val)});
3030
}
3131
void pop_back() {
3232
if (empty(r)) {
@@ -37,9 +37,9 @@ template<class T, class F> struct deq {
3737
}
3838
r.pop_back();
3939
}
40-
void push_front(T elem) {
40+
void push_front(T val) {
4141
l.push_back(
42-
{elem, empty(l) ? elem : op(elem, l.back()[1])});
42+
{val, empty(l) ? val : op(val, l.back()[1])});
4343
}
4444
void pop_front() {
4545
if (empty(l)) {

library/data_structures_[l,r)/uncommon/mode_query.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ const int b = 318; //!< sqrt(1e5)
33
//! https://noshi91.hatenablog.com/entry/2020/10/26/140105
44
struct mode_query {
55
int n;
6-
vi a, cnt, index_into_index;
7-
vector<vi> index;
6+
vi a, cnt, pos_idx;
7+
vector<vi> pos;
88
vector<vector<pii>>
99
mode_blocks; //!< {mode, cnt} of range of blocks
1010
//! @param a compressed array: 0 <= a[i] < n
1111
//! @time O(n * sqrt(n))
1212
//! @space O(n)
1313
mode_query(const vi& a):
14-
n(sz(a)), a(a), cnt(n), index_into_index(n), index(n),
14+
n(sz(a)), a(a), cnt(n), pos_idx(n), pos(n),
1515
mode_blocks((n + b - 1) / b,
1616
vector<pii>((n + b - 1) / b)) {
1717
rep(i, 0, n) {
18-
index_into_index[i] = sz(index[a[i]]);
19-
index[a[i]].push_back(i);
18+
pos_idx[i] = sz(pos[a[i]]);
19+
pos[a[i]].push_back(i);
2020
}
2121
for (int start = 0; start < n; start += b) {
2222
int mode = a[start];
@@ -51,17 +51,17 @@ struct mode_query {
5151
for (int i = l / b * b + b - 1; i >= l; i--)
5252
cnt[a[i]]++;
5353
for (int i = l / b * b + b - 1; i >= l; i--) {
54-
int idx = index_into_index[i];
55-
if (idx + res.second < sz(index[a[i]]) &&
56-
index[a[i]][idx + res.second] < r)
54+
int idx = pos_idx[i];
55+
if (idx + res.second < sz(pos[a[i]]) &&
56+
pos[a[i]][idx + res.second] < r)
5757
res = {a[i], cnt[a[i]] + res.second};
5858
cnt[a[i]]--;
5959
}
6060
rep(i, (r - 1) / b * b, r) cnt[a[i]]++;
6161
rep(i, (r - 1) / b * b, r) {
62-
int idx = index_into_index[i];
62+
int idx = pos_idx[i];
6363
if (idx >= res.second &&
64-
index[a[i]][idx - res.second] >= l)
64+
pos[a[i]][idx - res.second] >= l)
6565
res = {a[i], cnt[a[i]] + res.second};
6666
cnt[a[i]]--;
6767
}

0 commit comments

Comments
 (0)