From dfd17b98339405ae4b982aaf1aec6e4cf6b6d41f Mon Sep 17 00:00:00 2001 From: manoflearning <77jwk0724@gmail.com> Date: Wed, 31 Dec 2025 21:33:40 +0900 Subject: [PATCH] chore: change names --- AGENTS.md | 3 +- src/1-ds/erasable_pq.cpp | 4 +- src/1-ds/fenwick_tree.cpp | 12 ++--- src/1-ds/merge_sort_tree.cpp | 8 ++-- src/1-ds/segment_tree.cpp | 40 ++++++++-------- src/2-graph/bcc.cpp | 4 +- src/2-graph/euler_circuit.cpp | 4 +- src/2-graph/kth_shortest_path.cpp | 4 +- src/2-graph/offline_dynamic_connectivity.cpp | 4 +- src/2-graph/scc_2_sat.cpp | 8 ++-- src/2-graph/shortest_path.cpp | 8 ++-- tests/1-ds/test_erasable_pq.cpp | 6 +-- tests/1-ds/test_fenwick_tree.cpp | 14 +++--- tests/1-ds/test_merge_sort_tree.cpp | 10 ++-- tests/1-ds/test_segment_tree.cpp | 46 +++++++++---------- tests/2-graph/test_bcc.cpp | 8 ++-- tests/2-graph/test_euler_circuit.cpp | 6 +-- tests/2-graph/test_kth_shortest_path.cpp | 2 +- .../test_offline_dynamic_connectivity.cpp | 4 +- tests/2-graph/test_scc_2_sat.cpp | 4 +- tests/2-graph/test_shortest_path.cpp | 4 +- 21 files changed, 102 insertions(+), 101 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 29b0d04..a346ee3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -33,10 +33,11 @@ ## 주석과 문서화 (필수) 일관된 형식으로 친절하고 신호가 높은 문서를 작성하세요. +특히, 난이도가 높은 알고리즘/자료구조일수록 기억이 희미할 확률이 높으니 자세히 설명하세요. ### 1) 모듈 헤더 (재사용 가능한 각 컴포넌트마다) 상단 근처에 헤더 주석을 추가: -- what +- what: 단순히 알고리즘/자료구조의 이름을 적는 것이 아닌, 해당 구현체가 사용되는 맥락과 역할을 black box로 작성. - time; memory - constraint - usage diff --git a/src/1-ds/erasable_pq.cpp b/src/1-ds/erasable_pq.cpp index f16f974..1553736 100644 --- a/src/1-ds/erasable_pq.cpp +++ b/src/1-ds/erasable_pq.cpp @@ -3,9 +3,9 @@ // what: erasable priority queue via lazy deletion. // time: push/pop/erase O(log n); memory: O(n) // constraint: erase/top/pop assume valid; duplicates ok. -// usage: epq pq; pq.push(x); pq.erase(x); ll v = pq.top(); pq.pop(); +// usage: erase_pq pq; pq.push(x); pq.erase(x); ll v = pq.top(); pq.pop(); template > -struct epq { +struct erase_pq { priority_queue, cmp> q, del; int size() { return (int)q.size() - (int)del.size(); } bool empty() { return size() == 0; } diff --git a/src/1-ds/fenwick_tree.cpp b/src/1-ds/fenwick_tree.cpp index 3377e45..7ec06af 100644 --- a/src/1-ds/fenwick_tree.cpp +++ b/src/1-ds/fenwick_tree.cpp @@ -3,8 +3,8 @@ // what: fenwick tree (point add, prefix/range sum). // time: build O(n), update/query O(log n); memory: O(n) // constraint: 0-indexed; kth needs all values >= 0. -// usage: fenw fw; fw.build(a); fw.add(p, x); fw.sum(l, r); fw.kth(k); -struct fenw { +// usage: fenwick fw; fw.build(a); fw.add(p, x); fw.sum(l, r); fw.kth(k); +struct fenwick { int n; vector a, t; void init(int n_) { @@ -52,8 +52,8 @@ struct fenw { // what: fenwick tree (range add, point get). // time: update/query O(log n); memory: O(n) // constraint: 1-indexed; l <= r. -// usage: fenw_rp fw; fw.init(n); fw.add(l, r, x); ll v = fw.get(p); -struct fenw_rp { // 1-indexed +// usage: fenw_range fw; fw.init(n); fw.add(l, r, x); ll v = fw.get(p); +struct fenw_range { // 1-indexed int n; vector t; void init(int n_) { @@ -74,8 +74,8 @@ struct fenw_rp { // 1-indexed // what: 2D fenwick tree (point add, rectangle sum). // time: build O(n m), update/query O(log n log m); memory: O(n m) // constraint: 0-indexed; no bounds check. -// usage: fenw2d fw; fw.build(a); fw.add(x, y, v); fw.sum(x1, y1, x2, y2); -struct fenw2d { // 0-indexed +// usage: fenw_2d fw; fw.build(a); fw.add(x, y, v); fw.sum(x1, y1, x2, y2); +struct fenw_2d { // 0-indexed int n, m; vector> a, t; void init(int n_, int m_) { diff --git a/src/1-ds/merge_sort_tree.cpp b/src/1-ds/merge_sort_tree.cpp index 6f19641..12822e9 100644 --- a/src/1-ds/merge_sort_tree.cpp +++ b/src/1-ds/merge_sort_tree.cpp @@ -4,8 +4,8 @@ constexpr int MAX_MST = 1 << 17; // what: merge sort tree for count of values > k on a range. // time: build O(n log n), query O(log^2 n); memory: O(n log n) // constraint: MAX_MST >= n; values fit in int; 0-indexed [l, r]; build once. -// usage: mseg st; st.build(a); st.query(l, r, k); -struct mseg { +// usage: merge_seg st; st.build(a); st.query(l, r, k); +struct merge_seg { vector t[MAX_MST << 1]; void build(const vector &a) { for (int i = 0; i < sz(a); i++) @@ -27,8 +27,8 @@ struct mseg { // what: iter merge sort tree for count of values > k on a range. // time: build O(n log n), query O(log^2 n); memory: O(n log n) // constraint: MAX_MST >= n; values fit in int; 0-indexed [l, r]; build once. -// usage: mseg_it st; st.build(a); st.query(l, r, k); -struct mseg_it { +// usage: merge_seg_it st; st.build(a); st.query(l, r, k); +struct merge_seg_it { vector t[MAX_MST << 1]; void build(const vector &a) { for (int i = 0; i < sz(a); i++) diff --git a/src/1-ds/segment_tree.cpp b/src/1-ds/segment_tree.cpp index 1024c89..c020152 100644 --- a/src/1-ds/segment_tree.cpp +++ b/src/1-ds/segment_tree.cpp @@ -3,8 +3,8 @@ // what: segment tree (point set, range sum). // time: build O(n), update/query O(log n); memory: O(n) // constraint: 1-indexed [1, n]; a[0] unused. -// usage: segt st; st.build(a); st.set(p, v); st.query(l, r); -struct segt { +// usage: seg_tree st; st.build(a); st.set(p, v); st.query(l, r); +struct seg_tree { int flag; vector t; void build(const vector &a) { @@ -30,8 +30,8 @@ struct segt { // what: iter segment tree (point set, range sum). // time: build O(n), update/query O(log n); memory: O(n) // constraint: 0-indexed [l, r). -// usage: segti st; st.build(a); st.set(p, v); st.query(l, r); -struct segti { // 0-indexed +// usage: seg_tree_it st; st.build(a); st.set(p, v); st.query(l, r); +struct seg_tree_it { // 0-indexed int n; vector t; void build(const vector &a) { @@ -56,8 +56,8 @@ struct segti { // 0-indexed // what: segment tree for kth on freq array. // time: update/query O(log n); memory: O(n) // constraint: 1-indexed [1, n], values >= 0. -// usage: segk st; st.init(n); st.add(p, v); st.kth(k); -struct segk { +// usage: seg_tree_kth st; st.init(n); st.add(p, v); st.kth(k); +struct seg_tree_kth { int flag; vector t; void init(int n) { @@ -79,8 +79,8 @@ struct segk { // what: segment tree with range add + range sum. // time: update/query O(log n); memory: O(n) // constraint: 1-indexed [1, n]; a[0] unused. -// usage: seglz st; st.build(a); st.add(l, r, v); st.query(l, r); -struct seglz { +// usage: seg_tree_lz st; st.build(a); st.add(l, r, v); st.query(l, r); +struct seg_tree_lz { int flag; vector t, lz; void build(const vector &a) { @@ -128,8 +128,8 @@ struct seglz { // what: persistent segment tree (point set, range sum). // time: build O(n), update/query O(log n); memory: O(n log n) // constraint: 1-indexed [1, n]; a[0] unused. -// usage: pst st; st.build(n, a); st.set(p, v); st.query(l, r, ver); -struct pst { +// usage: seg_pst st; st.build(n, a); st.set(p, v); st.query(l, r, ver); +struct seg_pst { struct node { int l, r; ll val; @@ -201,13 +201,13 @@ struct pst { // what: dynamic seg tree (sparse, point add, range sum). // time: update/query O(log R); memory: O(k log R) // constraint: range [MAXL, MAXR], missing child => 0. -// usage: dyseg st; st.add(p, v); st.query(l, r); +// usage: seg_sparse st; st.add(p, v); st.query(l, r); constexpr int MAXL = 1, MAXR = 1000000; struct dnode { ll x; int l, r; }; -struct dyseg { +struct seg_sparse { vector t = {{0, -1, -1}, {0, -1, -1}}; void add(int p, ll x, int v = 1, int nl = MAXL, int nr = MAXR) { if (p < nl || nr < p) return; @@ -242,8 +242,8 @@ struct dyseg { // what: 2D segment tree (point set, rect sum). // time: build O(n^2), update/query O(log^2 n); memory: O(n^2) // constraint: 0-indexed square n x n. -// usage: seg2d st; st.build(a); st.set(x, y, v); st.query(x1, x2, y1, y2); -struct seg2d { // 0-indexed +// usage: seg_2d st; st.build(a); st.set(x, y, v); st.query(x1, x2, y1, y2); +struct seg_2d { // 0-indexed int n; vector> t; void build(const vector> &a) { @@ -287,18 +287,18 @@ struct seg2d { // 0-indexed // what: 2D seg tree with coord comp (offline). // time: prep O(q log q), update/query O(log^2 n); memory: O(q log q) -// constraint: call fmod/fqry first, then prep, then set/query. -// usage: seg2dc st(n); st.fmod(x, y); st.fqry(x1, x2, y1, y2); st.prep(); st.set(x, y, v); st.query(x1, x2, y1, y2); -struct seg2dc { // 0-indexed +// constraint: call mark_set/mark_qry first, then prep, then set/query. +// usage: seg2d_comp st(n); st.mark_set(x, y); st.mark_qry(x1, x2, y1, y2); st.prep(); st.set(x, y, v); st.query(x1, x2, y1, y2); +struct seg2d_comp { // 0-indexed int n; vector> a; vector> used; unordered_map mp; - seg2dc(int n) : n(n), a(2 * n), used(2 * n) {} - void fmod(int x, int y) { + seg2d_comp(int n) : n(n), a(2 * n), used(2 * n) {} + void mark_set(int x, int y) { for (x += n; x >= 1; x >>= 1) used[x].push_back(y); } - void fqry(int x1, int x2, int y1, int y2) { + void mark_qry(int x1, int x2, int y1, int y2) { for (x1 += n, x2 += n + 1; x1 < x2; x1 >>= 1, x2 >>= 1) { if (x1 & 1) { used[x1].push_back(y1); diff --git a/src/2-graph/bcc.cpp b/src/2-graph/bcc.cpp index 3993d16..5d6c76e 100644 --- a/src/2-graph/bcc.cpp +++ b/src/2-graph/bcc.cpp @@ -3,8 +3,8 @@ // what: biconnected components + articulation points/edges (undirected). // time: O(n+m); memory: O(n+m) // constraint: 1-indexed; no self-loops; recursion depth O(n). -// usage: bcc g; g.init(n); g.add(u,v); g.run(); // g.bccs, g.ap, g.ae -struct bcc { +// usage: bcc_graph g; g.init(n); g.add(u,v); g.run(); // g.bccs, g.ap, g.ae +struct bcc_graph { int n, tim; vector> adj; vector dfn, low, ap, st; diff --git a/src/2-graph/euler_circuit.cpp b/src/2-graph/euler_circuit.cpp index 39287d5..ba75601 100644 --- a/src/2-graph/euler_circuit.cpp +++ b/src/2-graph/euler_circuit.cpp @@ -3,8 +3,8 @@ // what: Euler circuit via Hierholzer (undirected multigraph, matrix). // time: O(n^2+m); memory: O(n^2) // constraint: 1-indexed; all nonzero-degree nodes connected. -// usage: ecir g; g.init(n); g.add(u,v); if (g.can()) auto path=g.run(1); -struct ecir { +// usage: euler_cir g; g.init(n); g.add(u,v); if (g.can()) auto path=g.run(1); +struct euler_cir { int n; vector> adj; vector nxt, path; diff --git a/src/2-graph/kth_shortest_path.cpp b/src/2-graph/kth_shortest_path.cpp index c165538..419924d 100644 --- a/src/2-graph/kth_shortest_path.cpp +++ b/src/2-graph/kth_shortest_path.cpp @@ -3,8 +3,8 @@ // what: k-th shortest walk (Eppstein-style, non-negative weights). // time: O((n+m)log m + klog k); memory: O(n+m+heap) // constraint: 1-indexed; w >= 0; n <= MAXN-1; recursion depth O(log m). -// usage: ksp g; g.init(n); g.add(u,v,w); auto v=g.run(s,e,k); -struct ksp { +// usage: kth_walk g; g.init(n); g.add(u,v,w); auto v=g.run(s,e,k); +struct kth_walk { static const int MAXN = 303030; static const ll INF = (ll)1e18; diff --git a/src/2-graph/offline_dynamic_connectivity.cpp b/src/2-graph/offline_dynamic_connectivity.cpp index 80f689c..33cc656 100644 --- a/src/2-graph/offline_dynamic_connectivity.cpp +++ b/src/2-graph/offline_dynamic_connectivity.cpp @@ -3,8 +3,8 @@ // what: offline dynamic connectivity with segment tree + rollback dsu. // time: O((n+q)log q); memory: O(n+q) // constraint: 1-indexed time; ops consistent; no parallel active edge. -// usage: odc g; g.init(n,q); g.add_op(i,op,u,v); g.build(); g.run(); -struct odc { +// usage: dyn_conn g; g.init(n,q); g.add_op(i,op,u,v); g.build(); g.run(); +struct dyn_conn { struct seg { int flg; vector> t; diff --git a/src/2-graph/scc_2_sat.cpp b/src/2-graph/scc_2_sat.cpp index 7e14332..aaa55b2 100644 --- a/src/2-graph/scc_2_sat.cpp +++ b/src/2-graph/scc_2_sat.cpp @@ -3,8 +3,8 @@ // what: SCC via Kosaraju. // time: O(n+m); memory: O(n+m) // constraint: directed; 1-indexed; recursion depth O(n). -// usage: scc_ko s; s.init(n); s.add(u,v); int c=s.run(); -struct scc_ko { +// usage: scc_kosa s; s.init(n); s.add(u,v); int c=s.run(); +struct scc_kosa { int n; vector> g, rg, sccs; vector vis, comp, ord; @@ -50,8 +50,8 @@ struct scc_ko { // what: SCC via Tarjan. // time: O(n+m); memory: O(n+m) // constraint: directed; 1-indexed; recursion depth O(n). -// usage: scc_ta s; s.init(n); s.add(u,v); int c=s.run(); -struct scc_ta { +// usage: scc_tarjan s; s.init(n); s.add(u,v); int c=s.run(); +struct scc_tarjan { int n, tim; vector> g, sccs; vector dfn, low, comp, st, ins; diff --git a/src/2-graph/shortest_path.cpp b/src/2-graph/shortest_path.cpp index 28ccaf6..c8cf9ae 100644 --- a/src/2-graph/shortest_path.cpp +++ b/src/2-graph/shortest_path.cpp @@ -3,8 +3,8 @@ // what: Dijkstra shortest path (non-negative weights). // time: O((n+m)log n); memory: O(n+m) // constraint: directed; 1-indexed; w >= 0. -// usage: dijk g; g.init(n); g.add(u,v,w); auto dist=g.run(s); -struct dijk { +// usage: dijkstra g; g.init(n); g.add(u,v,w); auto dist=g.run(s); +struct dijkstra { static const ll INF = (1LL << 62); int n; vector> adj; @@ -37,8 +37,8 @@ struct dijk { // what: Bellman-Ford shortest path. // time: O(nm); memory: O(n+m) // constraint: directed; 1-indexed; detects negative cycle reachable from s. -// usage: bell g; g.init(n); g.add(u,v,w); bool ok=g.run(s, dist); -struct bell { +// usage: bell_ford g; g.init(n); g.add(u,v,w); bool ok=g.run(s, dist); +struct bell_ford { static const ll INF = (1LL << 62); int n; vector> ed; diff --git a/tests/1-ds/test_erasable_pq.cpp b/tests/1-ds/test_erasable_pq.cpp index a5a1fda..9336e72 100644 --- a/tests/1-ds/test_erasable_pq.cpp +++ b/tests/1-ds/test_erasable_pq.cpp @@ -1,6 +1,6 @@ #include "../../src/1-ds/erasable_pq.cpp" -// what: tests for epq (erasable pq). +// what: tests for erase_pq (erasable pq). // time: random + edge cases; memory: O(n) // constraint: uses assert, fixed seed. // usage: g++ -std=c++17 test_erasable_pq.cpp && ./a.out @@ -19,7 +19,7 @@ ll pick_multiset(multiset &ms) { } void test_edge_cases() { - epq pq; + erase_pq pq; multiset ms; pq.push(5), ms.insert(5); @@ -43,7 +43,7 @@ void test_edge_cases() { } void test_randomized() { - epq pq; + erase_pq pq; multiset ms; for (int it = 0; it < 3000; it++) { diff --git a/tests/1-ds/test_fenwick_tree.cpp b/tests/1-ds/test_fenwick_tree.cpp index fb470a3..afec125 100644 --- a/tests/1-ds/test_fenwick_tree.cpp +++ b/tests/1-ds/test_fenwick_tree.cpp @@ -1,6 +1,6 @@ #include "../../src/1-ds/fenwick_tree.cpp" -// what: tests for fenw, fenw_rp, fenw2d. +// what: tests for fenwick, fenw_range, fenw_2d. // time: random + edge cases; memory: O(n^2) // constraint: uses assert, fixed seed. // usage: g++ -std=c++17 test_fenwick_tree.cpp && ./a.out @@ -34,7 +34,7 @@ ll sum_2d(const vector> &a, int x1, int y1, int x2, int y2) { } void test_fenwick_basic() { - fenw fw; + fenwick fw; vector a = {5}; fw.build(a); assert(fw.sum(0, 0) == 5); @@ -50,7 +50,7 @@ void test_fenwick_random() { vector a(n); for (int i = 0; i < n; i++) a[i] = rnd(0, 5); - fenw fw; + fenwick fw; fw.build(a); for (int it = 0; it < 5000; it++) { @@ -80,7 +80,7 @@ void test_fenwick_random() { } void test_fenwick_rp_basic() { - fenw_rp fw; + fenw_range fw; fw.init(1); fw.add(1, 1, 5); assert(fw.get(1) == 5); @@ -89,7 +89,7 @@ void test_fenwick_rp_basic() { void test_fenwick_rp_random() { int n = 40; vector a(n + 1, 0); - fenw_rp fw; + fenw_range fw; fw.init(n); for (int it = 0; it < 4000; it++) { @@ -108,7 +108,7 @@ void test_fenwick_rp_random() { } void test_fenwick_2d_basic() { - fenw2d fw; + fenw_2d fw; vector> a = {{3}}; fw.build(a); assert(fw.sum(0, 0, 0, 0) == 3); @@ -122,7 +122,7 @@ void test_fenwick_2d_random() { for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = rnd(-3, 3); - fenw2d fw; + fenw_2d fw; fw.build(a); for (int it = 0; it < 4000; it++) { diff --git a/tests/1-ds/test_merge_sort_tree.cpp b/tests/1-ds/test_merge_sort_tree.cpp index 2a6d706..5d8ef3b 100644 --- a/tests/1-ds/test_merge_sort_tree.cpp +++ b/tests/1-ds/test_merge_sort_tree.cpp @@ -1,6 +1,6 @@ #include "../../src/1-ds/merge_sort_tree.cpp" -// what: tests for mseg, mseg_it. +// what: tests for merge_seg, merge_seg_it. // time: random + edge cases; memory: O(n log n) // constraint: uses assert, fixed seed. // usage: g++ -std=c++17 test_merge_sort_tree.cpp && ./a.out @@ -19,7 +19,7 @@ int count_greater(const vector &a, int l, int r, int k) { void test_merge_sort_tree_basic() { vector a = {5}; - mseg st; + merge_seg st; st.build(a); assert(st.query(0, 0, 4) == 1); assert(st.query(0, 0, 5) == 0); @@ -30,7 +30,7 @@ void test_merge_sort_tree_random() { vector a(n); for (int i = 0; i < n; i++) a[i] = (int)rnd(-10, 10); - mseg st; + merge_seg st; st.build(a); for (int it = 0; it < 4000; it++) { @@ -43,7 +43,7 @@ void test_merge_sort_tree_random() { void test_merge_sort_tree_iter_basic() { vector a = {2}; - mseg_it st; + merge_seg_it st; st.build(a); assert(st.query(0, 0, 1) == 1); assert(st.query(0, 0, 2) == 0); @@ -54,7 +54,7 @@ void test_merge_sort_tree_iter_random() { vector a(n); for (int i = 0; i < n; i++) a[i] = (int)rnd(-10, 10); - mseg_it st; + merge_seg_it st; st.build(a); for (int it = 0; it < 4000; it++) { diff --git a/tests/1-ds/test_segment_tree.cpp b/tests/1-ds/test_segment_tree.cpp index ceae2ec..400b45c 100644 --- a/tests/1-ds/test_segment_tree.cpp +++ b/tests/1-ds/test_segment_tree.cpp @@ -1,6 +1,6 @@ #include "../../src/1-ds/segment_tree.cpp" -// what: tests for segt, segti, segk, seglz, pst, dyseg, seg2d, seg2dc. +// what: tests for seg_tree, seg_tree_it, seg_tree_kth, seg_tree_lz, seg_pst, seg_sparse, seg_2d, seg2d_comp. // time: random + edge cases; memory: O(n log n) // constraint: uses assert, fixed seed. // usage: g++ -std=c++17 test_segment_tree.cpp && ./a.out @@ -28,7 +28,7 @@ int kth_naive_freq(const vector &a, ll k) { void test_segt_basic() { vector a = {0, 3}; - segt st; + seg_tree st; st.build(a); assert(st.query(1, 1) == 3); st.set(1, -2); @@ -40,7 +40,7 @@ void test_segt_random() { vector a(n + 1, 0); for (int i = 1; i <= n; i++) a[i] = rnd(-5, 5); - segt st; + seg_tree st; st.build(a); for (int it = 0; it < 5000; it++) { @@ -60,7 +60,7 @@ void test_segt_random() { void test_segti_basic() { vector a = {4}; - segti st; + seg_tree_it st; st.build(a); assert(st.query(0, 1) == 4); st.set(0, 1); @@ -72,7 +72,7 @@ void test_segti_random() { vector a(n, 0); for (int i = 0; i < n; i++) a[i] = rnd(-5, 5); - segti st; + seg_tree_it st; st.build(a); for (int it = 0; it < 5000; it++) { @@ -94,7 +94,7 @@ void test_segti_random() { void test_segk_basic() { int n = 3; - segk st; + seg_tree_kth st; st.init(n); st.add(1, 2); st.add(3, 1); @@ -106,7 +106,7 @@ void test_segk_basic() { void test_segk_random() { int n = 40; vector a(n + 1, 0); - segk st; + seg_tree_kth st; st.init(n); for (int it = 0; it < 4000; it++) { @@ -128,7 +128,7 @@ void test_segk_random() { void test_seglz_basic() { vector a = {0, 1, 2}; - seglz st; + seg_tree_lz st; st.build(a); st.add(1, 2, 3); assert(st.query(1, 2) == 1 + 2 + 6); @@ -139,7 +139,7 @@ void test_seglz_random() { vector a(n + 1, 0); for (int i = 1; i <= n; i++) a[i] = rnd(-5, 5); - seglz st; + seg_tree_lz st; st.build(a); for (int it = 0; it < 4000; it++) { @@ -161,7 +161,7 @@ void test_seglz_random() { void test_pst_basic() { int n = 3; vector a = {0, 1, 2, 3}; - pst st; + seg_pst st; st.build(n, a); st.set(2, 5); assert(st.query(1, 3, 0) == 6); @@ -175,7 +175,7 @@ void test_pst_random() { for (int i = 1; i <= n; i++) a[i] = rnd(-5, 5); ver.push_back(a); - pst st; + seg_pst st; st.build(n, a); for (int it = 0; it < 2000; it++) { @@ -197,7 +197,7 @@ void test_pst_random() { } void test_dyseg_basic() { - dyseg st; + seg_sparse st; st.add(MAXL, 5); st.add(MAXR, -2); assert(st.query(MAXL, MAXL) == 5); @@ -206,7 +206,7 @@ void test_dyseg_basic() { } void test_dyseg_random() { - dyseg st; + seg_sparse st; map mp; int lo = 1, hi = 1000; @@ -237,7 +237,7 @@ ll sum_rect(const vector> &a, int x1, int y1, int x2, int y2) { void test_seg2d_basic() { vector> a = {{7}}; - seg2d st; + seg_2d st; st.build(a); assert(st.query(0, 0, 0, 0) == 7); st.set(0, 0, -1); @@ -250,7 +250,7 @@ void test_seg2d_random() { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) a[i][j] = rnd(-3, 3); - seg2d st; + seg_2d st; st.build(a); for (int it = 0; it < 3000; it++) { @@ -279,7 +279,7 @@ struct op2d { void test_seg2dc_basic() { int n = 1; - seg2dc st(n); + seg2d_comp st(n); vector ops; ops.push_back({0, 0, 0, 0, 0, 5}); ops.push_back({1, 0, 0, 0, 0, 0}); @@ -287,8 +287,8 @@ void test_seg2dc_basic() { ops.push_back({1, 0, 0, 0, 0, 0}); for (auto &op : ops) { - if (op.type == 0) st.fmod(op.x1, op.y1); - else st.fqry(op.x1, op.x2, op.y1, op.y2); + if (op.type == 0) st.mark_set(op.x1, op.y1); + else st.mark_qry(op.x1, op.x2, op.y1, op.y2); } st.prep(); @@ -301,7 +301,7 @@ void test_seg2dc_basic() { ll got = st.query(op.x1, op.x2, op.y1, op.y2); ll exp = sum_rect(a, op.x1, op.y1, op.x2, op.y2); if (got != exp) { - cerr << "seg2dc mismatch: " + cerr << "seg2d_comp mismatch: " << "x1=" << op.x1 << " x2=" << op.x2 << " y1=" << op.y1 << " y2=" << op.y2 << " got=" << got << " exp=" << exp << "\n"; @@ -313,7 +313,7 @@ void test_seg2dc_basic() { void test_seg2dc_random() { int n = 6; - seg2dc st(n); + seg2d_comp st(n); vector ops; int q = 2000; for (int i = 0; i < q; i++) { @@ -333,8 +333,8 @@ void test_seg2dc_random() { } for (auto &op : ops) { - if (op.type == 0) st.fmod(op.x1, op.y1); - else st.fqry(op.x1, op.x2, op.y1, op.y2); + if (op.type == 0) st.mark_set(op.x1, op.y1); + else st.mark_qry(op.x1, op.x2, op.y1, op.y2); } st.prep(); @@ -347,7 +347,7 @@ void test_seg2dc_random() { ll got = st.query(op.x1, op.x2, op.y1, op.y2); ll exp = sum_rect(a, op.x1, op.y1, op.x2, op.y2); if (got != exp) { - cerr << "seg2dc mismatch: " + cerr << "seg2d_comp mismatch: " << "x1=" << op.x1 << " x2=" << op.x2 << " y1=" << op.y1 << " y2=" << op.y2 << " got=" << got << " exp=" << exp << "\n"; diff --git a/tests/2-graph/test_bcc.cpp b/tests/2-graph/test_bcc.cpp index 98d25bf..695e0f1 100644 --- a/tests/2-graph/test_bcc.cpp +++ b/tests/2-graph/test_bcc.cpp @@ -1,6 +1,6 @@ #include "../../src/2-graph/bcc.cpp" -// what: tests for bcc. +// what: tests for bcc_graph. // time: random + brute checks; memory: O(n+m) // constraint: small n brute. // usage: g++ -std=c++17 test_bcc.cpp && ./a.out @@ -62,7 +62,7 @@ vector ae_na(int n, const vector &ed) { return ae; } -void chk_bcc(int n, const vector &ed, bcc &g) { +void chk_bcc(int n, const vector &ed, bcc_graph &g) { map cnt, got; for (auto [u, v] : ed) { if (u > v) swap(u, v); @@ -107,7 +107,7 @@ void chk_bcc(int n, const vector &ed, bcc &g) { void t_fix() { int n = 3; vector ed = {{1, 2}, {2, 3}}; - bcc g; + bcc_graph g; g.init(n); for (auto [u, v] : ed) g.add(u, v); g.run(); @@ -133,7 +133,7 @@ void t_rnd() { } ed.push_back({u, v}); } - bcc g; + bcc_graph g; g.init(n); for (auto [u, v] : ed) g.add(u, v); g.run(); diff --git a/tests/2-graph/test_euler_circuit.cpp b/tests/2-graph/test_euler_circuit.cpp index db45b80..7f4795b 100644 --- a/tests/2-graph/test_euler_circuit.cpp +++ b/tests/2-graph/test_euler_circuit.cpp @@ -53,7 +53,7 @@ bool can_na(int n, const vector> &cnt) { return 1; } -void add_ed(ecir &g, vector> &cnt, int u, int v) { +void add_ed(euler_cir &g, vector> &cnt, int u, int v) { g.add(u, v); if (u == v) cnt[u][u]++; else cnt[u][v]++, cnt[v][u]++; @@ -84,7 +84,7 @@ void chk_run(int n, const vector> &cnt, const vector &path) { void t_fix() { int n = 3; - ecir g; + euler_cir g; g.init(n); vector> cnt(n + 1, vector(n + 1)); add_ed(g, cnt, 1, 2); @@ -105,7 +105,7 @@ void t_rnd() { for (int it = 0; it < 200; it++) { int n = rnd(1, 6); int m = rnd(0, 8); - ecir g; + euler_cir g; g.init(n); vector> cnt(n + 1, vector(n + 1)); for (int i = 0; i < m; i++) { diff --git a/tests/2-graph/test_kth_shortest_path.cpp b/tests/2-graph/test_kth_shortest_path.cpp index 110aec4..9ec3daa 100644 --- a/tests/2-graph/test_kth_shortest_path.cpp +++ b/tests/2-graph/test_kth_shortest_path.cpp @@ -11,7 +11,7 @@ int rnd(int l, int r) { return dis(rng); } -ksp ks; +kth_walk ks; vector kth_na(int n, const vector> &g, int s, int e, int k) { vector cnt(n + 1); diff --git a/tests/2-graph/test_offline_dynamic_connectivity.cpp b/tests/2-graph/test_offline_dynamic_connectivity.cpp index a3dd3b7..416abec 100644 --- a/tests/2-graph/test_offline_dynamic_connectivity.cpp +++ b/tests/2-graph/test_offline_dynamic_connectivity.cpp @@ -51,7 +51,7 @@ void t_fix() { else ans[i] = conn(n, act, a, b); } - odc g; + dyn_conn g; g.init(n, q); for (int i = 1; i <= q; i++) g.add_op(i, op[i], u[i], v[i]); g.build(); @@ -100,7 +100,7 @@ void t_rnd() { } } - odc g; + dyn_conn g; g.init(n, q); for (int i = 1; i <= q; i++) g.add_op(i, op[i], u[i], v[i]); g.build(); diff --git a/tests/2-graph/test_scc_2_sat.cpp b/tests/2-graph/test_scc_2_sat.cpp index a8b2b63..0593310 100644 --- a/tests/2-graph/test_scc_2_sat.cpp +++ b/tests/2-graph/test_scc_2_sat.cpp @@ -72,13 +72,13 @@ void t_scc() { } auto cmp = cmp_na(n, g); - scc_ko s1; + scc_kosa s1; s1.init(n); for (int u = 1; u <= n; u++) for (int v : g[u]) s1.add(u, v); s1.run(); - scc_ta s2; + scc_tarjan s2; s2.init(n); for (int u = 1; u <= n; u++) for (int v : g[u]) s2.add(u, v); diff --git a/tests/2-graph/test_shortest_path.cpp b/tests/2-graph/test_shortest_path.cpp index 59e40a3..800dd76 100644 --- a/tests/2-graph/test_shortest_path.cpp +++ b/tests/2-graph/test_shortest_path.cpp @@ -31,7 +31,7 @@ void t_dijk() { int n = rnd(2, 7); int m = rnd(0, n * (n - 1)); vector> ed; - dijk dj; + dijkstra dj; dj.init(n); for (int i = 0; i < m; i++) { int u = rnd(1, n), v = rnd(1, n); @@ -57,7 +57,7 @@ void t_bell() { int n = rnd(2, 6); int m = rnd(0, n * (n - 1)); vector> ed; - bell bl; + bell_ford bl; bl.init(n); for (int i = 0; i < m; i++) { int u = rnd(1, n), v = rnd(1, n);