Skip to content

Commit ae0326d

Browse files
committed
refactor
1 parent d25d6e5 commit ae0326d

File tree

7 files changed

+39
-9
lines changed

7 files changed

+39
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ template<class T, class F> struct tree {
3131
}
3232
return op(x, y);
3333
}
34-
#include "seg_tree_uncommon/walk.hpp"
34+
#include "seg_tree_uncommon/max_right.hpp"
3535
};

library/data_structures_[l,r)/seg_tree_uncommon/walk.hpp renamed to library/data_structures_[l,r)/seg_tree_uncommon/max_right.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
int walk(int l, int r, const auto& f) {
1+
int max_right(int l, int r, const auto& f) {
22
for (T x = unit; l < r;) {
33
int u = l + n, v = __lg(min(u & -u, r - l));
44
if (T y = op(x, s[u >> v]); f(y)) l += 1 << v, x = y;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ template<class T, class F> struct tree {
3838
while (l <= r) x = op(x, s[nxt(l, r)]);
3939
return x;
4040
}
41-
#include "seg_tree_uncommon/walk.hpp"
41+
#include "seg_tree_uncommon/max_right.hpp"
4242
};

library/data_structures_[l,r]/seg_tree_uncommon/walk.hpp renamed to library/data_structures_[l,r]/seg_tree_uncommon/max_right.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
int walk(int l, int r, const auto& f) {
1+
int max_right(int l, int r, const auto& f) {
22
if (T x = s[l + n]; f(x))
33
for (l++; l <= r;) {
44
int u = l + n, v = __lg(min(u & -u, r - l + 1));

library/graphs/euler_walk.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
//! @code
3+
//! vector<basic_string<array<int, 2>>> adj(n);
4+
//! vector<pii> edges(m);
5+
//! r ep(i, 0, m) {
6+
//! int u, v;
7+
//! cin >> u >> v;
8+
//! u--, v--;
9+
//! adj[u] += {v, i};
10+
//! edges[i] = {u, v};
11+
//! }
12+
//! vector<pii> path = euler_path(adj, m, source);
13+
//! @endcode
14+
//! @time O(n + m)
15+
//! @space O(n + m)
16+
vector<pii> euler_path(auto& adj, int m, int s) {
17+
vi vis(m);
18+
vector<pii> path;
19+
auto dfs = [&](auto&& self, int u, int eu) -> void {
20+
while (!empty(adj[u])) {
21+
auto [v, ev] = adj[u].back();
22+
adj[u].pop_back();
23+
if (!vis[ev]) vis[ev] = 1, self(self, v, ev);
24+
}
25+
path.emplace_back(u, eu);
26+
};
27+
dfs(dfs, s, -1);
28+
ranges::reverse(path);
29+
return path;
30+
}

tests/library_checker_aizu_tests/data_structures/simple_tree_inc_walk.test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int main() {
2222
cout << st.query(k, k) << '\n';
2323
} else if (type == 3) {
2424
// returns first element in [k,n-1] such that sum > 0
25-
int idx = st.walk(k, n - 1,
25+
int idx = st.max_right(k, n - 1,
2626
[&](int sum) { return sum == 0; });
2727
if (idx == n) idx = -1;
2828
cout << idx << '\n';
@@ -32,7 +32,7 @@ int main() {
3232
if (total == 0) {
3333
cout << -1 << '\n';
3434
} else {
35-
cout << st.walk(0, k, [&](int sum) {
35+
cout << st.max_right(0, k, [&](int sum) {
3636
return sum < total;
3737
}) << '\n';
3838
}

tests/library_checker_aizu_tests/data_structures/simple_tree_walk.test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ int main() {
2121
cout << st.query(k, k + 1) << '\n';
2222
} else if (type == 3) {
2323
// returns first element in [k,n) such that sum > 0
24-
int idx =
25-
st.walk(k, n, [&](int sum) { return sum == 0; });
24+
int idx = st.max_right(k, n,
25+
[&](int sum) { return sum == 0; });
2626
if (idx == n) idx = -1;
2727
cout << idx << '\n';
2828
} else {
@@ -31,7 +31,7 @@ int main() {
3131
if (total == 0) {
3232
cout << -1 << '\n';
3333
} else {
34-
cout << st.walk(0, k + 1, [&](int sum) {
34+
cout << st.max_right(0, k + 1, [&](int sum) {
3535
return sum < total;
3636
}) << '\n';
3737
}

0 commit comments

Comments
 (0)