Skip to content

Commit 1dbbe8f

Browse files
committed
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.
1 parent bcc3b76 commit 1dbbe8f

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

library/trees/edge_cd.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ template<class G> void edge_cd(vector<G>& g, auto f) {
3030
if (m < 2) return;
3131
u = ctd(u, u, m);
3232
int sum = 0;
33-
auto it = partition(all(g[u]), [&](int v) {
33+
auto it = begin(ranges::partition(g[u], [&](int v) {
3434
ll x = sum + s[v];
3535
return x * x < m * (m - x) ? sum = x : 0;
36-
});
36+
}));
3737
f(u, it - begin(g[u]));
3838
G oth(it, end(g[u]));
3939
g[u].erase(it, end(g[u]));

library/trees/extra_members/virtual_tree.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ array<vi, 2> compress_tree(vi subset) {
1616
rep(i, 1, len)
1717
subset.push_back(lca(subset[i - 1], subset[i]));
1818
ranges::sort(subset, {}, proj);
19-
subset.erase(unique(all(subset)), end(subset));
19+
subset.erase(begin(ranges::unique(subset)), end(subset));
2020
return {
2121
mono_st(subset,
2222
[&](int u, int v) { return in_subtree(u, v); }),

0 commit comments

Comments
 (0)