From bcc3b767796fb2804ad41bdd35dec401243edec0 Mon Sep 17 00:00:00 2001 From: Cameron Custer Date: Sun, 12 Jul 2026 10:47:05 -0700 Subject: [PATCH 1/2] use ranges::iota over std::iota for full-range calls Convert the full-range std::iota(begin, end, v) calls to ranges::iota(range, v). This favors the ranges algorithms already used throughout the library and removes an all(...) macro expansion on main. Partial-range calls (e.g. iterator sub-ranges) and std::partial_sum are left as-is: partial_sum has no ranges equivalent, and partial ranges read more clearly with explicit iterators. --- library/dsu/line_tree.hpp | 2 +- library/graphs/mst.hpp | 2 +- .../strongly_connected_components/offline_incremental_scc.hpp | 2 +- library/graphs/uncommon/complement_graph_ccs.hpp | 2 +- library/math/prime_sieve/calc_linear_sieve.hpp | 2 +- library/math/prime_sieve/calc_sieve.hpp | 2 +- library/strings/longest_common_subsequence/lcs_dp.hpp | 2 +- library/strings/manacher/longest_palindrome_query.hpp | 2 +- library/strings/suffix_array/suffix_array.hpp | 4 ++-- library/strings/suffix_array/suffix_array_short.hpp | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/library/dsu/line_tree.hpp b/library/dsu/line_tree.hpp index 17b64c0af..9358c3cd6 100644 --- a/library/dsu/line_tree.hpp +++ b/library/dsu/line_tree.hpp @@ -20,7 +20,7 @@ struct line_tree { vi p, last; vector edge; line_tree(int n): p(n, -1), last(n), edge(n, {-1, -1}) { - iota(all(last), 0); + ranges::iota(last, 0); } int size(int u) { return -p[f(u)]; } int f(int u) { return p[u] < 0 ? u : p[u] = f(p[u]); } diff --git a/library/graphs/mst.hpp b/library/graphs/mst.hpp index 0e6ea8344..a8a669cbc 100644 --- a/library/graphs/mst.hpp +++ b/library/graphs/mst.hpp @@ -10,7 +10,7 @@ pair mst(const vector>& w_eds, int n) { vi order(sz(w_eds)); - iota(all(order), 0); + ranges::iota(order, 0); ranges::sort(order, {}, [&](int i) { return w_eds[i][2]; }); DSU dsu(n); diff --git a/library/graphs/strongly_connected_components/offline_incremental_scc.hpp b/library/graphs/strongly_connected_components/offline_incremental_scc.hpp index 10a63390c..e4dd62510 100644 --- a/library/graphs/strongly_connected_components/offline_incremental_scc.hpp +++ b/library/graphs/strongly_connected_components/offline_incremental_scc.hpp @@ -14,7 +14,7 @@ vi offline_incremental_scc(vector> eds, int n) { int m = sz(eds); vi ids(n, -1), joins(m, m), idx(m), vs(n), scc_id; - iota(all(idx), 0); + ranges::iota(idx, 0); vector g; auto dnc = [&](this auto&& dnc, auto el, auto er, int tl, int tr) { diff --git a/library/graphs/uncommon/complement_graph_ccs.hpp b/library/graphs/uncommon/complement_graph_ccs.hpp index 0da0f6c72..18ebc9ef4 100644 --- a/library/graphs/uncommon/complement_graph_ccs.hpp +++ b/library/graphs/uncommon/complement_graph_ccs.hpp @@ -12,7 +12,7 @@ vi get_complement_graph_ccs(const auto& g) { int n = sz(g); vi cc_id(n), unseen(n); - iota(all(unseen), 0); + ranges::iota(unseen, 0); vector is_g(n); for (int cnt = 0; !empty(unseen); cnt++) { int s = unseen.back(); diff --git a/library/math/prime_sieve/calc_linear_sieve.hpp b/library/math/prime_sieve/calc_linear_sieve.hpp index 0104524c4..863e6f445 100644 --- a/library/math/prime_sieve/calc_linear_sieve.hpp +++ b/library/math/prime_sieve/calc_linear_sieve.hpp @@ -2,7 +2,7 @@ //! @time O(mx) //! @space O(mx) vi primes, sieve(1001); //!< min prime factor -iota(all(sieve), 0); +ranges::iota(sieve, 0); rep(i, 2, sz(sieve)) { if (sieve[i] == i) primes.push_back(i); for (int prime : primes) { diff --git a/library/math/prime_sieve/calc_sieve.hpp b/library/math/prime_sieve/calc_sieve.hpp index 3fcbc1b01..4f2023b71 100644 --- a/library/math/prime_sieve/calc_sieve.hpp +++ b/library/math/prime_sieve/calc_sieve.hpp @@ -2,7 +2,7 @@ //! @time O(mx * log(log mx)) //! @space O(mx) vi sieve(1001); //!< min prime factor -iota(all(sieve), 0); +ranges::iota(sieve, 0); for (int i = 2; i * i < sz(sieve); i++) if (sieve[i] == i) for (int j = i * i; j < sz(sieve); j += i) diff --git a/library/strings/longest_common_subsequence/lcs_dp.hpp b/library/strings/longest_common_subsequence/lcs_dp.hpp index 3fe997236..1892c7092 100644 --- a/library/strings/longest_common_subsequence/lcs_dp.hpp +++ b/library/strings/longest_common_subsequence/lcs_dp.hpp @@ -10,7 +10,7 @@ template struct lcs_dp { T t; vi dp; - lcs_dp(const T& t): t(t), dp(sz(t)) { iota(all(dp), 0); } + lcs_dp(const T& t): t(t), dp(sz(t)) { ranges::iota(dp, 0); } void push_onto_s(int c) { int v = -1; rep(i, 0, sz(t)) if (c == t[i] || dp[i] < v) diff --git a/library/strings/manacher/longest_palindrome_query.hpp b/library/strings/manacher/longest_palindrome_query.hpp index 499619d4f..fcfc6514c 100644 --- a/library/strings/manacher/longest_palindrome_query.hpp +++ b/library/strings/manacher/longest_palindrome_query.hpp @@ -11,7 +11,7 @@ struct longest_pal_query { //! @space O(n log n) for rmq, everything else is O(n) longest_pal_query(const auto& s): man(manacher(s)) { vi init(sz(man)); - iota(all(init), 0); + ranges::iota(init, 0); rmq = {init, [&](int i1, int i2) { return len(i1) < len(i2) ? i2 : i1; }}; diff --git a/library/strings/suffix_array/suffix_array.hpp b/library/strings/suffix_array/suffix_array.hpp index 1b8ed5375..f63766693 100644 --- a/library/strings/suffix_array/suffix_array.hpp +++ b/library/strings/suffix_array/suffix_array.hpp @@ -37,10 +37,10 @@ auto get_sa(const auto& s, int max_num) { int n = sz(s); vi sa(n), sa_inv(all(s)), lcp(n - 1); - iota(all(sa), 0); + ranges::iota(sa, 0); for (int i = 0; i < n; i = max(1, 2 * i)) { vi y(sa_inv), freq(max_num); - iota(all(sa_inv), n - i); + ranges::iota(sa_inv, n - i); ranges::copy_if(sa, begin(sa_inv) + i, [&](int& x) { return (x -= i) >= 0; }); for (int x : y) freq[x]++; diff --git a/library/strings/suffix_array/suffix_array_short.hpp b/library/strings/suffix_array/suffix_array_short.hpp index ea383be66..2d196ea8a 100644 --- a/library/strings/suffix_array/suffix_array_short.hpp +++ b/library/strings/suffix_array/suffix_array_short.hpp @@ -13,7 +13,7 @@ auto sa_short(const auto& s) { int n = sz(s), b = 6; vi sa(n), sa_inv(all(s)), lcp(n - 1), t(n); - iota(all(sa), 0); + ranges::iota(sa, 0); for (int j = 1; j <= n; j *= b) { swap(t, sa_inv); auto cmp = [&](int i1, int i2) { From 1dbbe8f0e751c8b20b4e5008ef694e9f5afc5c64 Mon Sep 17 00:00:00 2001 From: Cameron Custer Date: Sun, 12 Jul 2026 10:52:48 -0700 Subject: [PATCH 2/2] use ranges::unique and ranges::partition for full-range calls Convert the remaining full-range std algorithm calls to their ranges:: equivalents: - virtual_tree: unique(all(subset)) -> begin(ranges::unique(subset)) - edge_cd: partition(all(g[u]), ...) -> begin(ranges::partition(g[u], ...)) ranges::unique / ranges::partition return a subrange, so begin(...) yields the iterator the erase / offset logic needs. Partial-range calls (iterator sub-ranges) and std::partial_sum are still left as-is: partial_sum has no ranges equivalent, and partial ranges read more clearly with explicit iterators. --- library/trees/edge_cd.hpp | 4 ++-- library/trees/extra_members/virtual_tree.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/trees/edge_cd.hpp b/library/trees/edge_cd.hpp index 496520209..d175ea0df 100644 --- a/library/trees/edge_cd.hpp +++ b/library/trees/edge_cd.hpp @@ -30,10 +30,10 @@ template void edge_cd(vector& g, auto f) { if (m < 2) return; u = ctd(u, u, m); int sum = 0; - auto it = partition(all(g[u]), [&](int v) { + auto it = begin(ranges::partition(g[u], [&](int v) { ll x = sum + s[v]; return x * x < m * (m - x) ? sum = x : 0; - }); + })); f(u, it - begin(g[u])); G oth(it, end(g[u])); g[u].erase(it, end(g[u])); diff --git a/library/trees/extra_members/virtual_tree.hpp b/library/trees/extra_members/virtual_tree.hpp index 824ac32b9..dfbd3d9f8 100644 --- a/library/trees/extra_members/virtual_tree.hpp +++ b/library/trees/extra_members/virtual_tree.hpp @@ -16,7 +16,7 @@ array compress_tree(vi subset) { rep(i, 1, len) subset.push_back(lca(subset[i - 1], subset[i])); ranges::sort(subset, {}, proj); - subset.erase(unique(all(subset)), end(subset)); + subset.erase(begin(ranges::unique(subset)), end(subset)); return { mono_st(subset, [&](int u, int v) { return in_subtree(u, v); }),