From 9324463f36580f22888ff8fe8ea695cbad0fd734 Mon Sep 17 00:00:00 2001 From: manoflearning <77jwk0724@gmail.com> Date: Sun, 4 Jan 2026 01:58:59 +0900 Subject: [PATCH 1/6] chore: apply pb macro --- src/1-ds/li_chao_tree.cpp | 6 ++--- src/1-ds/merge_sort_tree.cpp | 4 ++-- src/1-ds/segment_tree.cpp | 20 ++++++++-------- src/2-graph/bcc.cpp | 20 ++++++++-------- src/2-graph/euler_circuit.cpp | 2 +- src/2-graph/kth_shortest_path.cpp | 10 ++++---- src/2-graph/offline_dynamic_connectivity.cpp | 4 ++-- src/2-graph/scc_2_sat.cpp | 24 +++++++++---------- src/2-graph/shortest_path.cpp | 4 ++-- src/3-tree/centroid_decomp.cpp | 6 ++--- src/3-tree/hld.cpp | 4 ++-- src/3-tree/lca_sparse_table.cpp | 4 ++-- src/3-tree/tree_composition.cpp | 12 +++++----- src/3-tree/tree_exchange_argument.cpp | 4 ++-- src/4-optimizations/flow.cpp | 22 ++++++++--------- src/5-string/aho_corasick.cpp | 6 ++--- src/5-string/kmp_algorithm.cpp | 2 +- src/5-string/rabin_karp_algorithm.cpp | 2 +- src/5-string/trie.cpp | 4 ++-- src/6-geometry/bulldozer_trick.cpp | 6 ++--- src/6-geometry/convex_hull.cpp | 4 ++-- src/6-geometry/half_plane_intersection.cpp | 8 +++---- src/6-geometry/segment_intersection.cpp | 4 ++-- src/7-math/misc_sqrt.cpp | 10 ++++---- src/7-math/nt_mr_rho.cpp | 2 +- src/7-math/nt_sieve.cpp | 10 ++++---- src/8-misc/dp_opt.cpp | 2 +- src/8-misc/lis_in_o_nlogn.cpp | 8 +++---- .../sqrt_decomposition_mos_algorithm.cpp | 2 +- .../system_of_difference_constraints.cpp | 2 +- src/common/common.hpp | 4 ++-- tests/1-ds/test_li_chao_tree.cpp | 6 ++--- tests/1-ds/test_segment_tree.cpp | 20 ++++++++-------- tests/2-graph/test_bcc.cpp | 14 +++++------ tests/2-graph/test_kth_shortest_path.cpp | 8 +++---- .../test_offline_dynamic_connectivity.cpp | 4 ++-- tests/2-graph/test_scc_2_sat.cpp | 4 ++-- tests/2-graph/test_shortest_path.cpp | 6 ++--- tests/3-tree/test_centroid_decomp.cpp | 10 ++++---- tests/3-tree/test_hld.cpp | 12 +++++----- tests/3-tree/test_lca_sparse_table.cpp | 4 ++-- tests/3-tree/test_tree_composition.cpp | 10 ++++---- tests/3-tree/test_tree_exchange_argument.cpp | 12 +++++----- tests/4-optimizations/test_flow.cpp | 16 ++++++------- tests/5-string/test_aho_corasick.cpp | 4 ++-- tests/5-string/test_kmp_algorithm.cpp | 4 ++-- tests/5-string/test_manachers_algorithm.cpp | 2 +- tests/5-string/test_rabin_karp_algorithm.cpp | 4 ++-- tests/5-string/test_suffix_array.cpp | 2 +- tests/5-string/test_trie.cpp | 2 +- tests/5-string/test_z_algorithm.cpp | 2 +- tests/6-geometry/test_bulldozer_trick.cpp | 22 ++++++++--------- tests/6-geometry/test_convex_hull.cpp | 4 ++-- .../test_half_plane_intersection.cpp | 24 +++++++++---------- .../test_minimum_enclosing_circle.cpp | 2 +- tests/6-geometry/test_ray_casting.cpp | 2 +- tests/6-geometry/test_rotating_callipers.cpp | 2 +- .../6-geometry/test_segment_intersection.cpp | 4 ++-- tests/6-geometry/test_sort_by_angular.cpp | 2 +- tests/7-math/test_misc_sqrt.cpp | 6 ++--- tests/7-math/test_nt_crt.cpp | 2 +- tests/7-math/test_nt_mr_rho.cpp | 4 ++-- tests/7-math/test_nt_sieve.cpp | 4 ++-- tests/8-misc/test_kitamasa.cpp | 2 +- .../test_system_of_difference_constraints.cpp | 2 +- 65 files changed, 225 insertions(+), 225 deletions(-) diff --git a/src/1-ds/li_chao_tree.cpp b/src/1-ds/li_chao_tree.cpp index 7f30cc8..9b498c8 100644 --- a/src/1-ds/li_chao_tree.cpp +++ b/src/1-ds/li_chao_tree.cpp @@ -22,7 +22,7 @@ struct li_chao { void init(ll xl, ll xr) { // goal: set x-range and clear tree. t.clear(); - t.push_back({xl, xr, -1, -1, LINE_E}); + t.pb({xl, xr, -1, -1, LINE_E}); } void add(lc_line nw, int v = 0) { // goal: insert a new line into the segment. @@ -40,14 +40,14 @@ struct li_chao { t[v].ln = hi; if (t[v].r == -1) { t[v].r = sz(t); - t.push_back({mid + 1, xr, -1, -1, LINE_E}); + t.pb({mid + 1, xr, -1, -1, LINE_E}); } add(lo, t[v].r); } else { t[v].ln = lo; if (t[v].l == -1) { t[v].l = sz(t); - t.push_back({xl, mid, -1, -1, LINE_E}); + t.pb({xl, mid, -1, -1, LINE_E}); } add(hi, t[v].l); } diff --git a/src/1-ds/merge_sort_tree.cpp b/src/1-ds/merge_sort_tree.cpp index 7f6aba8..50b5b70 100644 --- a/src/1-ds/merge_sort_tree.cpp +++ b/src/1-ds/merge_sort_tree.cpp @@ -10,7 +10,7 @@ struct merge_seg { void build(const vector &a) { // goal: build sorted lists for each node. for (int i = 0; i < sz(a); i++) - t[i + MAX_MST].push_back(a[i]); + t[i + MAX_MST].pb(a[i]); for (int i = MAX_MST - 1; i >= 1; i--) { t[i].resize(sz(t[i << 1]) + sz(t[i << 1 | 1])); merge(all(t[i << 1]), all(t[i << 1 | 1]), t[i].begin()); @@ -35,7 +35,7 @@ struct merge_seg_it { void build(const vector &a) { // goal: build sorted lists for each node. for (int i = 0; i < sz(a); i++) - t[i + MAX_MST].push_back(a[i]); + t[i + MAX_MST].pb(a[i]); for (int i = MAX_MST - 1; i >= 1; i--) { t[i].resize(sz(t[i << 1]) + sz(t[i << 1 | 1])); merge(all(t[i << 1]), all(t[i << 1 | 1]), t[i].begin()); diff --git a/src/1-ds/segment_tree.cpp b/src/1-ds/segment_tree.cpp index 9ed43da..6f595d6 100644 --- a/src/1-ds/segment_tree.cpp +++ b/src/1-ds/segment_tree.cpp @@ -151,14 +151,14 @@ struct seg_pst { vector t; vector root; - void newnd() { t.push_back({-1, -1, 0}); } + void newnd() { t.pb({-1, -1, 0}); } void build(int n_, const vector &a) { // goal: build initial version. n = n_; t.clear(); root.clear(); newnd(); - root.push_back(0); + root.pb(0); build(1, n, root[0], a); } void build(int l, int r, int v, const vector &a) { @@ -179,7 +179,7 @@ struct seg_pst { void set(int p, ll val) { // goal: create new version with a[p] = val. newnd(); - root.push_back(sz(t) - 1); + root.pb(sz(t) - 1); set(p, val, 1, n, root[sz(root) - 2], root.back()); } void set(int p, ll val, int l, int r, int v1, int v2) { @@ -246,13 +246,13 @@ struct seg_sparse { if (p <= mid) { if (t[v].l == -1) { t[v].l = sz(t); - t.push_back({0, -1, -1}); + t.pb({0, -1, -1}); } add(p, x, t[v].l, nl, mid); } else { if (t[v].r == -1) { t[v].r = sz(t); - t.push_back({0, -1, -1}); + t.pb({0, -1, -1}); } add(p, x, t[v].r, mid + 1, nr); } @@ -331,18 +331,18 @@ struct seg2d_comp { // 0-indexed seg2d_comp(int n) : n(n), a(2 * n), used(2 * n) {} void mark_set(int x, int y) { // goal: record y-coordinates that will be updated. - for (x += n; x >= 1; x >>= 1) used[x].push_back(y); + for (x += n; x >= 1; x >>= 1) used[x].pb(y); } void mark_qry(int x1, int x2, int y1, int y2) { // goal: record y-coordinates needed for queries. for (x1 += n, x2 += n + 1; x1 < x2; x1 >>= 1, x2 >>= 1) { if (x1 & 1) { - used[x1].push_back(y1); - used[x1++].push_back(y2); + used[x1].pb(y1); + used[x1++].pb(y2); } if (x2 & 1) { - used[--x2].push_back(y1); - used[x2].push_back(y2); + used[--x2].pb(y1); + used[x2].pb(y2); } } } diff --git a/src/2-graph/bcc.cpp b/src/2-graph/bcc.cpp index a95b928..c59257d 100644 --- a/src/2-graph/bcc.cpp +++ b/src/2-graph/bcc.cpp @@ -25,9 +25,9 @@ struct bcc_graph { } void add(int u, int v) { int id = sz(ed); - ed.push_back({u, v}); - adj[u].push_back({v, id}); - adj[v].push_back({u, id}); + ed.pb({u, v}); + adj[u].pb({v, id}); + adj[v].pb({u, id}); } void dfs(int v, int pe) { dfn[v] = low[v] = ++tim; @@ -37,27 +37,27 @@ struct bcc_graph { if (dfn[to] != -1) { // edge: back edge to ancestor. low[v] = min(low[v], dfn[to]); - if (dfn[to] < dfn[v]) st.push_back(id); + if (dfn[to] < dfn[v]) st.pb(id); continue; } - st.push_back(id); + st.pb(id); ch++; dfs(to, id); low[v] = min(low[v], low[to]); - if (pe != -1 && low[to] >= dfn[v]) ap.push_back(v); - if (low[to] > dfn[v]) ae.push_back({min(v, to), max(v, to)}); + if (pe != -1 && low[to] >= dfn[v]) ap.pb(v); + if (low[to] > dfn[v]) ae.pb({min(v, to), max(v, to)}); if (low[to] >= dfn[v]) { vector comp; while (1) { int eid = st.back(); st.pop_back(); - comp.push_back(ed[eid]); + comp.pb(ed[eid]); if (eid == id) break; } - bccs.push_back(comp); + bccs.pb(comp); } } - if (pe == -1 && ch > 1) ap.push_back(v); + if (pe == -1 && ch > 1) ap.pb(v); } void run() { for (int v = 1; v <= n; v++) diff --git a/src/2-graph/euler_circuit.cpp b/src/2-graph/euler_circuit.cpp index df6e943..265e431 100644 --- a/src/2-graph/euler_circuit.cpp +++ b/src/2-graph/euler_circuit.cpp @@ -58,7 +58,7 @@ struct euler_cir { dfs(i); } } - path.push_back(v); + path.pb(v); } vector run(int s = 1) { // result: Euler circuit starting from s (if exists). diff --git a/src/2-graph/kth_shortest_path.cpp b/src/2-graph/kth_shortest_path.cpp index bd1382b..c86093a 100644 --- a/src/2-graph/kth_shortest_path.cpp +++ b/src/2-graph/kth_shortest_path.cpp @@ -19,7 +19,7 @@ struct kth_walk { vector h; void init() { h.assign(1, {{0, 0}, 0, 0, 0}); } int mk(pll x) { - h.push_back({x, 0, 0, 1}); + h.pb({x, 0, 0, 1}); return sz(h) - 1; } void norm(int x) { @@ -43,8 +43,8 @@ struct kth_walk { hp.init(); } void add(int u, int v, ll w) { - g[u].push_back({w, v}); - rg[v].push_back({w, u}); + g[u].pb({w, v}); + rg[v].pb({w, u}); } vector run(int s, int e, int k) { @@ -62,7 +62,7 @@ struct kth_walk { if (vis[x]) continue; vis[x] = 1; nxt[x] = p; - ord.push_back(x); + ord.pb(x); for (auto [c, y] : rg[x]) { if (!vis[y] && dist[y] > d + c) { dist[y] = d + c; @@ -92,7 +92,7 @@ struct kth_walk { while (sz(ans) < k && !pq2.empty()) { auto [d, x] = pq2.top(); pq2.pop(); - ans.push_back(dist[s] + d); + ans.pb(dist[s] + d); int y = hp.h[x].x.sc; if (rt[y]) pq2.push({d + hp.h[rt[y]].x.fr, rt[y]}); if (hp.h[x].l) pq2.push({d - hp.h[x].x.fr + hp.h[hp.h[x].l].x.fr, hp.h[x].l}); diff --git a/src/2-graph/offline_dynamic_connectivity.cpp b/src/2-graph/offline_dynamic_connectivity.cpp index 040e982..465d6dc 100644 --- a/src/2-graph/offline_dynamic_connectivity.cpp +++ b/src/2-graph/offline_dynamic_connectivity.cpp @@ -18,7 +18,7 @@ struct dyn_conn { if (nr == -1) nr = flg; if (r < nl || nr < l) return; if (l <= nl && nr <= r) { - t[n].push_back(e); + t[n].pb(e); return; } int mid = (nl + nr) >> 1; @@ -48,7 +48,7 @@ struct dyn_conn { if (siz[a] < siz[b]) swap(a, b); par[b] = a; siz[a] += siz[b]; - st.push_back(b); + st.pb(b); return 1; } void undo() { diff --git a/src/2-graph/scc_2_sat.cpp b/src/2-graph/scc_2_sat.cpp index 7f1ccde..88a3a4f 100644 --- a/src/2-graph/scc_2_sat.cpp +++ b/src/2-graph/scc_2_sat.cpp @@ -19,18 +19,18 @@ struct scc_kosa { ord.clear(); } void add(int u, int v) { - g[u].push_back(v); - rg[v].push_back(u); + g[u].pb(v); + rg[v].pb(u); } void dfs1(int v) { vis[v] = 1; for (int to : rg[v]) if (!vis[to]) dfs1(to); - ord.push_back(v); + ord.pb(v); } void dfs2(int v, int id) { comp[v] = id; - sccs[id].push_back(v); + sccs[id].pb(v); for (int to : g[v]) if (comp[to] == -1) dfs2(to, id); } @@ -40,7 +40,7 @@ struct scc_kosa { reverse(all(ord)); for (int v : ord) { if (comp[v] != -1) continue; - sccs.push_back({}); + sccs.pb({}); dfs2(v, sz(sccs) - 1); } return sz(sccs); @@ -67,10 +67,10 @@ struct scc_tarjan { ins.assign(n + 1, 0); st.clear(); } - void add(int u, int v) { g[u].push_back(v); } + void add(int u, int v) { g[u].pb(v); } void dfs(int v) { dfn[v] = low[v] = ++tim; - st.push_back(v); + st.pb(v); ins[v] = 1; for (int to : g[v]) { if (dfn[to] == -1) { @@ -81,14 +81,14 @@ struct scc_tarjan { } } if (low[v] != dfn[v]) return; - sccs.push_back({}); + sccs.pb({}); int id = sz(sccs) - 1; while (1) { int x = st.back(); st.pop_back(); ins[x] = 0; comp[x] = id; - sccs[id].push_back(x); + sccs[id].pb(x); if (x == v) break; } } @@ -126,12 +126,12 @@ struct two_sat { } void add(int a, int b) { // goal: (a v b) == (!a -> b) & (!b -> a) - g[id(-a)].push_back(id(b)); - g[id(-b)].push_back(id(a)); + g[id(-a)].pb(id(b)); + g[id(-b)].pb(id(a)); } void dfs(int v) { dfn[v] = low[v] = ++tim; - st.push_back(v); + st.pb(v); ins[v] = 1; for (int to : g[v]) { if (dfn[to] == -1) { diff --git a/src/2-graph/shortest_path.cpp b/src/2-graph/shortest_path.cpp index 854cd6b..3dfc933 100644 --- a/src/2-graph/shortest_path.cpp +++ b/src/2-graph/shortest_path.cpp @@ -14,7 +14,7 @@ struct dijkstra { n = n_; adj.assign(n + 1, {}); } - void add(int u, int v, ll w) { adj[u].push_back({w, v}); } + void add(int u, int v, ll w) { adj[u].pb({w, v}); } vector run(int s) { // result: dist[i] = shortest distance from s to i. vector dist(n + 1, INF); @@ -50,7 +50,7 @@ struct bell_ford { n = n_; ed.clear(); } - void add(int u, int v, ll w) { ed.push_back({u, v, w}); } + void add(int u, int v, ll w) { ed.pb({u, v, w}); } bool run(int s, vector &dist) { // result: false if a negative cycle is reachable. dist.assign(n + 1, INF); diff --git a/src/3-tree/centroid_decomp.cpp b/src/3-tree/centroid_decomp.cpp index 0b87991..8837a41 100644 --- a/src/3-tree/centroid_decomp.cpp +++ b/src/3-tree/centroid_decomp.cpp @@ -19,8 +19,8 @@ struct cen_decomp { used.assign(n + 1, 0); } void add(int u, int v) { - adj[u].push_back(v); - adj[v].push_back(u); + adj[u].pb(v); + adj[v].pb(u); } int get_sz(int v, int p) { // goal: subtree sizes for centroid search. @@ -43,7 +43,7 @@ struct cen_decomp { int tot = get_sz(v, p); int c = get_cent(v, p, tot); par[c] = p; - if (p) chd[p].push_back(c); + if (p) chd[p].pb(c); used[c] = 1; for (int to : adj[c]) if (!used[to]) build(to, c); diff --git a/src/3-tree/hld.cpp b/src/3-tree/hld.cpp index 035d48a..d02bf92 100644 --- a/src/3-tree/hld.cpp +++ b/src/3-tree/hld.cpp @@ -23,8 +23,8 @@ struct hld_tree { in.assign(n + 1, 0); } void add(int u, int v) { - adj[u].push_back(v); - adj[v].push_back(u); + adj[u].pb(v); + adj[v].pb(u); } int dfs_sz(int v, int p) { // goal: compute subtree sizes and heavy child. diff --git a/src/3-tree/lca_sparse_table.cpp b/src/3-tree/lca_sparse_table.cpp index 905ad65..17a415a 100644 --- a/src/3-tree/lca_sparse_table.cpp +++ b/src/3-tree/lca_sparse_table.cpp @@ -18,8 +18,8 @@ struct lca_sparse { dep.assign(n + 1, 0); } void add(int u, int v) { - adj[u].push_back(v); - adj[v].push_back(u); + adj[u].pb(v); + adj[v].pb(u); } void dfs(int v, int p) { // goal: set parent and depth. diff --git a/src/3-tree/tree_composition.cpp b/src/3-tree/tree_composition.cpp index a80c689..88ea68a 100644 --- a/src/3-tree/tree_composition.cpp +++ b/src/3-tree/tree_composition.cpp @@ -22,8 +22,8 @@ struct tree_comp { tim = 0; } void add(int u, int v) { - adj[u].push_back(v); - adj[v].push_back(u); + adj[u].pb(v); + adj[v].pb(u); } void dfs(int v, int p) { // goal: build tin/tout, depth, and parents. @@ -62,18 +62,18 @@ struct tree_comp { sort(all(vs), [&](int a, int b) { return tin[a] < tin[b]; }); vs.erase(unique(all(vs)), vs.end()); int m = sz(vs); - for (int i = 0; i + 1 < m; i++) vs.push_back(lca(vs[i], vs[i + 1])); + for (int i = 0; i + 1 < m; i++) vs.pb(lca(vs[i], vs[i + 1])); sort(all(vs), [&](int a, int b) { return tin[a] < tin[b]; }); vs.erase(unique(all(vs)), vs.end()); for (int v : vs) vt_adj[v].clear(); vector st; - st.push_back(vs[0]); + st.pb(vs[0]); for (int i = 1; i < sz(vs); i++) { int v = vs[i]; // invariant: stack is ancestor chain. while (!is_anc(st.back(), v)) st.pop_back(); - vt_adj[st.back()].push_back(v); - st.push_back(v); + vt_adj[st.back()].pb(v); + st.pb(v); } return vs; } diff --git a/src/3-tree/tree_exchange_argument.cpp b/src/3-tree/tree_exchange_argument.cpp index 3abf125..d0ab5c6 100644 --- a/src/3-tree/tree_exchange_argument.cpp +++ b/src/3-tree/tree_exchange_argument.cpp @@ -43,8 +43,8 @@ struct tree_xchg { ds.init(n); } void add(int u, int v) { - adj[u].push_back(v); - adj[v].push_back(u); + adj[u].pb(v); + adj[v].pb(u); } void dfs(int v, int p) { par[v] = p; diff --git a/src/4-optimizations/flow.cpp b/src/4-optimizations/flow.cpp index 21e656a..38b26cd 100644 --- a/src/4-optimizations/flow.cpp +++ b/src/4-optimizations/flow.cpp @@ -36,8 +36,8 @@ struct dinic { // goal: add forward + reverse edge edge a{v, (int)g[v].size(), cap}; edge b{u, (int)g[u].size(), 0}; - g[u].push_back(a); - g[v].push_back(b); + g[u].pb(a); + g[v].pb(b); return {u, (int)g[u].size() - 1}; } @@ -126,7 +126,7 @@ struct hk { void add_edge(int l, int r) { // goal: add edge from left to right - g[l].push_back(r); + g[l].pb(r); } bool bfs() { @@ -214,8 +214,8 @@ struct mcmf { // goal: add forward + reverse edge with costs edge a{v, (int)g[v].size(), cap, cost}; edge b{u, (int)g[u].size(), 0, -cost}; - g[u].push_back(a); - g[v].push_back(b); + g[u].pb(a); + g[v].pb(b); return {u, (int)g[u].size() - 1}; } @@ -340,7 +340,7 @@ struct lr_dinic { // goal: store lower bounds via node demands demand[u] -= lo; demand[v] += lo; - edges.push_back({mf.add_edge(u, v, hi - lo), lo}); + edges.pb({mf.add_edge(u, v, hi - lo), lo}); return (int)edges.size() - 1; } @@ -355,10 +355,10 @@ struct lr_dinic { int ss = n, tt = n + 1; for (int i = 0; i < n; i++) { if (demand[i] > 0) { - aux.push_back(mf.add_edge(ss, i, demand[i])); + aux.pb(mf.add_edge(ss, i, demand[i])); total += demand[i]; } else if (demand[i] < 0) { - aux.push_back(mf.add_edge(i, tt, -demand[i])); + aux.pb(mf.add_edge(i, tt, -demand[i])); } } return total; @@ -429,7 +429,7 @@ struct lr_mcmf { demand[u] -= lo; demand[v] += lo; base_cost += lo * cost; - edges.push_back({mf.add_edge(u, v, hi - lo, cost), lo}); + edges.pb({mf.add_edge(u, v, hi - lo, cost), lo}); return (int)edges.size() - 1; } @@ -444,10 +444,10 @@ struct lr_mcmf { int ss = n, tt = n + 1; for (int i = 0; i < n; i++) { if (demand[i] > 0) { - aux.push_back(mf.add_edge(ss, i, demand[i], 0)); + aux.pb(mf.add_edge(ss, i, demand[i], 0)); total += demand[i]; } else if (demand[i] < 0) { - aux.push_back(mf.add_edge(i, tt, -demand[i], 0)); + aux.pb(mf.add_edge(i, tt, -demand[i], 0)); } } return total; diff --git a/src/5-string/aho_corasick.cpp b/src/5-string/aho_corasick.cpp index 9d87406..f21cbf6 100644 --- a/src/5-string/aho_corasick.cpp +++ b/src/5-string/aho_corasick.cpp @@ -26,10 +26,10 @@ struct aho_corasick { int c = ch - 'a'; if (nxt[v][c] == -1) { nxt[v][c] = sz(nxt); - nxt.push_back({}); + nxt.pb({}); nxt.back().fill(-1); - fail.push_back(0); - out.push_back(0); + fail.pb(0); + out.pb(0); } v = nxt[v][c]; } diff --git a/src/5-string/kmp_algorithm.cpp b/src/5-string/kmp_algorithm.cpp index 0e434bb..5c32e49 100644 --- a/src/5-string/kmp_algorithm.cpp +++ b/src/5-string/kmp_algorithm.cpp @@ -23,7 +23,7 @@ vector kmp_match(const string &t, const string &p) { while (j && t[i] != p[j]) j = pi[j - 1]; if (t[i] != p[j]) continue; if (j == sz(p) - 1) { - res.push_back(i - (sz(p) - 1)); + res.pb(i - (sz(p) - 1)); j = pi[j]; } else { j++; diff --git a/src/5-string/rabin_karp_algorithm.cpp b/src/5-string/rabin_karp_algorithm.cpp index cbcbb80..5ea0b87 100644 --- a/src/5-string/rabin_karp_algorithm.cpp +++ b/src/5-string/rabin_karp_algorithm.cpp @@ -46,6 +46,6 @@ vector rk_match(const string &t, const string &p) { hp.build(p); pll hp0 = hp.get(0, m); for (int i = 0; i + m <= n; i++) - if (ht.get(i, i + m) == hp0) res.push_back(i); + if (ht.get(i, i + m) == hp0) res.pb(i); return res; } diff --git a/src/5-string/trie.cpp b/src/5-string/trie.cpp index 51ee707..ad652db 100644 --- a/src/5-string/trie.cpp +++ b/src/5-string/trie.cpp @@ -25,9 +25,9 @@ struct trie { int c = ch - 'a'; if (nxt[v][c] == -1) { nxt[v][c] = sz(nxt); - nxt.push_back({}); + nxt.pb({}); nxt.back().fill(-1); - term.push_back(0); + term.pb(0); } v = nxt[v][c]; } diff --git a/src/6-geometry/bulldozer_trick.cpp b/src/6-geometry/bulldozer_trick.cpp index 373f8d1..ad66628 100644 --- a/src/6-geometry/bulldozer_trick.cpp +++ b/src/6-geometry/bulldozer_trick.cpp @@ -35,7 +35,7 @@ void bulldozer(vector &p, F f) { dx = -dx, dy = -dy; swap(u, v); } - ln.push_back({u, v, dx, dy}); + ln.pb({u, v, dx, dy}); } } sort(all(ln)); @@ -49,8 +49,8 @@ void bulldozer(vector &p, F f) { for (int k = i; k < j; k++) { int u = ln[k].u, v = ln[k].v; ll c = -dy * base[u].x + dx * base[u].y; - mp[c].push_back(u); - mp[c].push_back(v); + mp[c].pb(u); + mp[c].pb(v); } for (auto &it : mp) { auto &vec = it.sc; diff --git a/src/6-geometry/convex_hull.cpp b/src/6-geometry/convex_hull.cpp index c925465..60c6cad 100644 --- a/src/6-geometry/convex_hull.cpp +++ b/src/6-geometry/convex_hull.cpp @@ -13,12 +13,12 @@ vector convex_hull(vector p) { vector lo, hi; for (auto &v : p) { while (sz(lo) >= 2 && cross(lo[sz(lo) - 2], lo.back(), v) <= 0) lo.pop_back(); - lo.push_back(v); + lo.pb(v); } for (int i = n - 1; i >= 0; i--) { auto v = p[i]; while (sz(hi) >= 2 && cross(hi[sz(hi) - 2], hi.back(), v) <= 0) hi.pop_back(); - hi.push_back(v); + hi.pb(v); } lo.pop_back(); hi.pop_back(); diff --git a/src/6-geometry/half_plane_intersection.cpp b/src/6-geometry/half_plane_intersection.cpp index 8c339f4..a134d7a 100644 --- a/src/6-geometry/half_plane_intersection.cpp +++ b/src/6-geometry/half_plane_intersection.cpp @@ -42,12 +42,12 @@ vector hpi(vector ln) { vector v; for (auto &l : ln) { if (v.empty()) { - v.push_back(l); + v.pb(l); continue; } ptd da = dir(v.back()), db = dir(l); if (!eq(cross(da, db), 0)) { - v.push_back(l); + v.pb(l); continue; } if (cross(da, l.s - v.back().s) > 0) v.back() = l; @@ -56,7 +56,7 @@ vector hpi(vector ln) { for (auto &l : v) { while (sz(dq) >= 2 && bad(dq[sz(dq) - 2], dq.back(), l)) dq.pop_back(); while (sz(dq) >= 2 && bad(dq[0], dq[1], l)) dq.pop_front(); - dq.push_back(l); + dq.pb(l); } while (sz(dq) >= 3 && bad(dq[sz(dq) - 2], dq.back(), dq[0])) dq.pop_back(); while (sz(dq) >= 3 && bad(dq[0], dq[1], dq.back())) dq.pop_front(); @@ -66,7 +66,7 @@ vector hpi(vector ln) { ptd p; if (line_inter(dq[i].s, dq[i].t, dq[(i + 1) % sz(dq)].s, dq[(i + 1) % sz(dq)].t, p)) { - poly.push_back(p); + poly.pb(p); } } } diff --git a/src/6-geometry/segment_intersection.cpp b/src/6-geometry/segment_intersection.cpp index 35f32a9..a852057 100644 --- a/src/6-geometry/segment_intersection.cpp +++ b/src/6-geometry/segment_intersection.cpp @@ -19,8 +19,8 @@ bool seg_inter_p(const pt &a, const pt &b, const pt &c, const pt &d, ptd &out) { return 1; } ptd pa{(ld)a.x, (ld)a.y}; - ptd pb{(ld)b.x, (ld)b.y}; + ptd p_b{(ld)b.x, (ld)b.y}; ptd pc{(ld)c.x, (ld)c.y}; ptd pd{(ld)d.x, (ld)d.y}; - return line_inter(pa, pb, pc, pd, out); + return line_inter(pa, p_b, pc, pd, out); } diff --git a/src/7-math/misc_sqrt.cpp b/src/7-math/misc_sqrt.cpp index b0e06eb..a6a30bf 100644 --- a/src/7-math/misc_sqrt.cpp +++ b/src/7-math/misc_sqrt.cpp @@ -11,8 +11,8 @@ struct sqrt_alg { vector d; for (ll i = 1; i <= x / i; i++) { if (x % i) continue; - d.push_back(i); - if (i * i != x) d.push_back(x / i); + d.pb(i); + if (i * i != x) d.pb(x / i); } sort(all(d)); return d; @@ -22,16 +22,16 @@ struct sqrt_alg { // result: prime factors of x (with repetition). vector p; while ((x & 1) == 0) { - p.push_back(2); + p.pb(2); x >>= 1; } for (ll i = 3; i <= x / i; i += 2) { while (x % i == 0) { - p.push_back(i); + p.pb(i); x /= i; } } - if (x > 1) p.push_back(x); + if (x > 1) p.pb(x); return p; } }; diff --git a/src/7-math/nt_mr_rho.cpp b/src/7-math/nt_mr_rho.cpp index 305a8cf..76e97ac 100644 --- a/src/7-math/nt_mr_rho.cpp +++ b/src/7-math/nt_mr_rho.cpp @@ -63,7 +63,7 @@ struct pollard_rho { static void rec(ll n, vector &out) { if (n == 1) return; if (miller_rabin::is_prime(n)) { - out.push_back(n); + out.pb(n); return; } ll d = rho(n); diff --git a/src/7-math/nt_sieve.cpp b/src/7-math/nt_sieve.cpp index e32754a..8a4451b 100644 --- a/src/7-math/nt_sieve.cpp +++ b/src/7-math/nt_sieve.cpp @@ -26,9 +26,9 @@ struct era_sieve { for (ll j = i * i; j <= n; j += i << 1) isp[j] = 0; } primes.clear(); - if (n >= 2) primes.push_back(2); + if (n >= 2) primes.pb(2); for (int i = 3; i <= n; i += 2) - if (isp[i]) primes.push_back(i); + if (isp[i]) primes.pb(i); } bool is_prime(int x) const { return x >= 2 && x <= n && isp[x]; } @@ -57,7 +57,7 @@ struct lin_sieve { for (int i = 2; i <= n; i++) { if (!lp[i]) { lp[i] = i; - primes.push_back(i); + primes.pb(i); mu[i] = -1; phi[i] = i - 1; } @@ -83,7 +83,7 @@ struct lin_sieve { vector ret; while (x > 1) { int p = lp[x]; - ret.push_back(p); + ret.pb(p); x /= p; } return ret; @@ -96,7 +96,7 @@ struct lin_sieve { int p = lp[x]; int e = 0; while (x % p == 0) x /= p, e++; - ret.push_back({p, e}); + ret.pb({p, e}); } return ret; } diff --git a/src/8-misc/dp_opt.cpp b/src/8-misc/dp_opt.cpp index a519d46..bf806a5 100644 --- a/src/8-misc/dp_opt.cpp +++ b/src/8-misc/dp_opt.cpp @@ -35,7 +35,7 @@ struct cht_mono { st.pop_back(); } if (st.empty()) cur.x = NEG_INF; - st.push_back(cur); + st.pb(cur); } ll get(ll x) const { diff --git a/src/8-misc/lis_in_o_nlogn.cpp b/src/8-misc/lis_in_o_nlogn.cpp index c418849..6b0f1db 100644 --- a/src/8-misc/lis_in_o_nlogn.cpp +++ b/src/8-misc/lis_in_o_nlogn.cpp @@ -10,7 +10,7 @@ int lis_len(const vector &a) { vector tail; for (ll x : a) { auto it = lower_bound(tail.begin(), tail.end(), x); - if (it == tail.end()) tail.push_back(x); + if (it == tail.end()) tail.pb(x); else *it = x; } return sz(tail); @@ -26,8 +26,8 @@ vector lis_seq(const vector &a) { ll x = a[i]; int pos = lower_bound(tail.begin(), tail.end(), x) - tail.begin(); if (pos == sz(tail)) { - tail.push_back(x); - tail_idx.push_back(i); + tail.pb(x); + tail_idx.pb(i); } else { tail[pos] = x; tail_idx[pos] = i; @@ -37,7 +37,7 @@ vector lis_seq(const vector &a) { vector ret; int cur = tail_idx.empty() ? -1 : tail_idx.back(); while (cur != -1) { - ret.push_back(a[cur]); + ret.pb(a[cur]); cur = pre[cur]; } reverse(all(ret)); diff --git a/src/8-misc/sqrt_decomposition_mos_algorithm.cpp b/src/8-misc/sqrt_decomposition_mos_algorithm.cpp index 4f1b6bd..4e1de81 100644 --- a/src/8-misc/sqrt_decomposition_mos_algorithm.cpp +++ b/src/8-misc/sqrt_decomposition_mos_algorithm.cpp @@ -21,7 +21,7 @@ struct mo { q.clear(); } - void add_query(int l, int r, int idx) { q.push_back({l, r, idx}); } + void add_query(int l, int r, int idx) { q.pb({l, r, idx}); } template void run(Add add, Del del, Out out) { diff --git a/src/8-misc/system_of_difference_constraints.cpp b/src/8-misc/system_of_difference_constraints.cpp index 19ce17e..45c632a 100644 --- a/src/8-misc/system_of_difference_constraints.cpp +++ b/src/8-misc/system_of_difference_constraints.cpp @@ -24,7 +24,7 @@ struct diff_cons { void add_le(int u, int v, ll w) { // goal: x_v - x_u <= w - g[u].push_back({v, w}); + g[u].pb({v, w}); } void add_ge(int u, int v, ll w) { diff --git a/src/common/common.hpp b/src/common/common.hpp index e28326e..5e8de73 100644 --- a/src/common/common.hpp +++ b/src/common/common.hpp @@ -2,14 +2,14 @@ #include using namespace std; - using ll = long long; using ld = long double; using ull = unsigned long long; using pii = pair; using pll = pair; - #define fr first #define sc second +#define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() diff --git a/tests/1-ds/test_li_chao_tree.cpp b/tests/1-ds/test_li_chao_tree.cpp index da90d97..9c8fbb0 100644 --- a/tests/1-ds/test_li_chao_tree.cpp +++ b/tests/1-ds/test_li_chao_tree.cpp @@ -23,12 +23,12 @@ void test_li_chao_basic() { li_chao lc; lc.init(-5, 5); vector lns; - lns.push_back({2, 1}); + lns.pb({2, 1}); lc.add(lns.back()); assert(lc.query(-5) == max_naive(lns, -5)); assert(lc.query(5) == max_naive(lns, 5)); - lns.push_back({2, -3}); + lns.pb({2, -3}); lc.add(lns.back()); assert(lc.query(0) == max_naive(lns, 0)); } @@ -44,7 +44,7 @@ void test_li_chao_random() { if (op == 0) { ll a = rnd(-5, 5); ll b = rnd(-20, 20); - lns.push_back({a, b}); + lns.pb({a, b}); lc.add(lns.back()); } else { ll x = rnd(xl, xr); diff --git a/tests/1-ds/test_segment_tree.cpp b/tests/1-ds/test_segment_tree.cpp index dfbd828..1cda5a1 100644 --- a/tests/1-ds/test_segment_tree.cpp +++ b/tests/1-ds/test_segment_tree.cpp @@ -173,7 +173,7 @@ void test_pst_random() { vector> ver; vector a(n + 1, 0); for (int i = 1; i <= n; i++) a[i] = rnd(-5, 5); - ver.push_back(a); + ver.pb(a); seg_pst st; st.build(n, a); @@ -185,7 +185,7 @@ void test_pst_random() { ll v = rnd(-5, 5); vector nw = ver.back(); nw[p] = v; - ver.push_back(nw); + ver.pb(nw); st.set(p, v); } else { int id = (int)rnd(0, (int)ver.size() - 1); @@ -217,7 +217,7 @@ void test_pst_kth_random() { vector> ver; vector a(n + 1, 0); for (int i = 1; i <= n; i++) a[i] = rnd(0, 3); - ver.push_back(a); + ver.pb(a); seg_pst st; st.build(n, a); @@ -229,7 +229,7 @@ void test_pst_kth_random() { ll v = rnd(0, 5); vector nw = ver.back(); nw[p] = v; - ver.push_back(nw); + ver.pb(nw); st.set(p, v); } else { int id = (int)rnd(0, (int)ver.size() - 1); @@ -329,10 +329,10 @@ void test_seg2dc_basic() { int n = 1; seg2d_comp st(n); vector ops; - ops.push_back({0, 0, 0, 0, 0, 5}); - ops.push_back({1, 0, 0, 0, 0, 0}); - ops.push_back({0, 0, 0, 0, 0, -2}); - ops.push_back({1, 0, 0, 0, 0, 0}); + ops.pb({0, 0, 0, 0, 0, 5}); + ops.pb({1, 0, 0, 0, 0, 0}); + ops.pb({0, 0, 0, 0, 0, -2}); + ops.pb({1, 0, 0, 0, 0, 0}); for (auto &op : ops) { if (op.type == 0) st.mark_set(op.x1, op.y1); @@ -370,13 +370,13 @@ void test_seg2dc_random() { int x = (int)rnd(0, n - 1); int y = (int)rnd(0, n - 1); ll v = rnd(-5, 5); - ops.push_back({0, x, 0, y, 0, v}); + ops.pb({0, x, 0, y, 0, v}); } else { int x1 = (int)rnd(0, n - 1); int x2 = (int)rnd(x1, n - 1); int y1 = (int)rnd(0, n - 1); int y2 = (int)rnd(y1, n - 1); - ops.push_back({1, x1, x2, y1, y2, 0}); + ops.pb({1, x1, x2, y1, y2, 0}); } } diff --git a/tests/2-graph/test_bcc.cpp b/tests/2-graph/test_bcc.cpp index 695e0f1..5508f79 100644 --- a/tests/2-graph/test_bcc.cpp +++ b/tests/2-graph/test_bcc.cpp @@ -17,8 +17,8 @@ int ccnt(int n, const vector &ed, int sv, int se) { if (i == se) continue; int u = ed[i].fr, v = ed[i].sc; if (u == sv || v == sv) continue; - adj[u].push_back(v); - adj[v].push_back(u); + adj[u].pb(v); + adj[v].pb(u); } vector vis(n + 1); int cnt = 0; @@ -43,7 +43,7 @@ vector ap_na(int n, const vector &ed) { int base = ccnt(n, ed, 0, -1); vector ap; for (int v = 1; v <= n; v++) - if (ccnt(n, ed, v, -1) > base) ap.push_back(v); + if (ccnt(n, ed, v, -1) > base) ap.pb(v); return ap; } @@ -54,7 +54,7 @@ vector ae_na(int n, const vector &ed) { if (ccnt(n, ed, 0, i) > base) { int u = ed[i].fr, v = ed[i].sc; if (u > v) swap(u, v); - ae.push_back({u, v}); + ae.pb({u, v}); } } sort(all(ae)); @@ -81,8 +81,8 @@ void chk_bcc(int n, const vector &ed, bcc_graph &g) { vector>> adj(n + 1); for (int i = 0; i < sz(comp); i++) { int u = comp[i].fr, v = comp[i].sc; - adj[u].push_back({v, i}); - adj[v].push_back({u, i}); + adj[u].pb({v, i}); + adj[v].pb({u, i}); } for (int i = 0; i < sz(comp); i++) { int u = comp[i].fr, v = comp[i].sc; @@ -131,7 +131,7 @@ void t_rnd() { i--; continue; } - ed.push_back({u, v}); + ed.pb({u, v}); } bcc_graph g; g.init(n); diff --git a/tests/2-graph/test_kth_shortest_path.cpp b/tests/2-graph/test_kth_shortest_path.cpp index 9ec3daa..e8c5f25 100644 --- a/tests/2-graph/test_kth_shortest_path.cpp +++ b/tests/2-graph/test_kth_shortest_path.cpp @@ -23,7 +23,7 @@ vector kth_na(int n, const vector> &g, int s, int e, int k) { pq.pop(); cnt[v]++; if (cnt[v] > k) continue; - if (v == e) res.push_back(d); + if (v == e) res.pb(d); if (cnt[v] <= k) for (auto [w, to] : g[v]) pq.push({d + w, to}); } @@ -33,8 +33,8 @@ vector kth_na(int n, const vector> &g, int s, int e, int k) { void t_fix() { int n = 3; vector> g(n + 1); - g[1].push_back({1, 2}); - g[2].push_back({1, 3}); + g[1].pb({1, 2}); + g[2].pb({1, 3}); ks.init(n); ks.add(1, 2, 1); ks.add(2, 3, 1); @@ -52,7 +52,7 @@ void t_rnd() { for (int i = 0; i < m; i++) { int u = rnd(1, n), v = rnd(1, n); ll w = rnd(1, 5); - g[u].push_back({w, v}); + g[u].pb({w, v}); ks.add(u, v, w); } int s = rnd(1, n), e = rnd(1, n), k = rnd(1, 10); diff --git a/tests/2-graph/test_offline_dynamic_connectivity.cpp b/tests/2-graph/test_offline_dynamic_connectivity.cpp index 416abec..e446d07 100644 --- a/tests/2-graph/test_offline_dynamic_connectivity.cpp +++ b/tests/2-graph/test_offline_dynamic_connectivity.cpp @@ -15,8 +15,8 @@ int conn(int n, const set &act, int s, int e) { if (s == e) return 1; vector> adj(n + 1); for (auto [u, v] : act) { - adj[u].push_back(v); - adj[v].push_back(u); + adj[u].pb(v); + adj[v].pb(u); } vector vis(n + 1); queue q; diff --git a/tests/2-graph/test_scc_2_sat.cpp b/tests/2-graph/test_scc_2_sat.cpp index 0593310..9565f46 100644 --- a/tests/2-graph/test_scc_2_sat.cpp +++ b/tests/2-graph/test_scc_2_sat.cpp @@ -68,7 +68,7 @@ void t_scc() { vector> g(n + 1); for (int i = 0; i < m; i++) { int u = rnd(1, n), v = rnd(1, n); - g[u].push_back(v); + g[u].pb(v); } auto cmp = cmp_na(n, g); @@ -104,7 +104,7 @@ void t_sat() { int a = rnd(1, n), b = rnd(1, n); if (rnd(0, 1)) a = -a; if (rnd(0, 1)) b = -b; - cl.push_back({a, b}); + cl.pb({a, b}); } vector val; bool ok2 = sat_br(n, cl, val); diff --git a/tests/2-graph/test_shortest_path.cpp b/tests/2-graph/test_shortest_path.cpp index 800dd76..63dcc1a 100644 --- a/tests/2-graph/test_shortest_path.cpp +++ b/tests/2-graph/test_shortest_path.cpp @@ -36,7 +36,7 @@ void t_dijk() { for (int i = 0; i < m; i++) { int u = rnd(1, n), v = rnd(1, n); ll w = rnd(0, 9); - ed.push_back({u, v, w}); + ed.pb({u, v, w}); dj.add(u, v, w); } auto d = floy(n, ed); @@ -62,7 +62,7 @@ void t_bell() { for (int i = 0; i < m; i++) { int u = rnd(1, n), v = rnd(1, n); ll w = rnd(-5, 9); - ed.push_back({u, v, w}); + ed.pb({u, v, w}); bl.add(u, v, w); } auto d = floy(n, ed); @@ -97,7 +97,7 @@ void t_floy() { for (int i = 0; i < m; i++) { int u = rnd(1, n), v = rnd(1, n); ll w = rnd(-5, 9); - ed.push_back({u, v, w}); + ed.pb({u, v, w}); fl.add(u, v, w); } auto d = floy(n, ed); diff --git a/tests/3-tree/test_centroid_decomp.cpp b/tests/3-tree/test_centroid_decomp.cpp index e15e797..3404b05 100644 --- a/tests/3-tree/test_centroid_decomp.cpp +++ b/tests/3-tree/test_centroid_decomp.cpp @@ -12,8 +12,8 @@ int rnd(int l, int r) { } void add_edge(vector> &adj, int u, int v) { - adj[u].push_back(v); - adj[v].push_back(u); + adj[u].pb(v); + adj[v].pb(u); } vector> gen_tree(int n) { @@ -47,8 +47,8 @@ vector get_nodes(int v, const vector> &chd) { while (!st.empty()) { int x = st.back(); st.pop_back(); - res.push_back(x); - for (int to : chd[x]) st.push_back(to); + res.pb(x); + for (int to : chd[x]) st.pb(to); } return res; } @@ -121,7 +121,7 @@ void check_one(const vector> &adj) { for (int x : cd.chd[c]) { int lab = first[x]; assert(lab); - labs.push_back(lab); + labs.pb(lab); auto nodes_x = get_nodes(x, cd.chd); for (int v : nodes_x) assert(first[v] == lab); } diff --git a/tests/3-tree/test_hld.cpp b/tests/3-tree/test_hld.cpp index bfe0a08..e498e74 100644 --- a/tests/3-tree/test_hld.cpp +++ b/tests/3-tree/test_hld.cpp @@ -29,10 +29,10 @@ vector path_nodes(int n, const vector> &adj, int s, int e) { vector res; int v = e; while (v != par[v]) { - res.push_back(v); + res.pb(v); v = par[v]; } - res.push_back(s); + res.pb(s); return res; } @@ -40,8 +40,8 @@ void t_fix() { int n = 4; vector> adj(n + 1); auto add = [&](int u, int v) { - adj[u].push_back(v); - adj[v].push_back(u); + adj[u].pb(v); + adj[v].pb(u); }; add(1, 2); add(2, 3); @@ -68,8 +68,8 @@ void t_rnd() { vector> adj(n + 1); for (int v = 2; v <= n; v++) { par[v] = rnd(1, v - 1); - adj[v].push_back(par[v]); - adj[par[v]].push_back(v); + adj[v].pb(par[v]); + adj[par[v]].pb(v); } hld_tree h; h.init(n); diff --git a/tests/3-tree/test_lca_sparse_table.cpp b/tests/3-tree/test_lca_sparse_table.cpp index d595a91..251db0f 100644 --- a/tests/3-tree/test_lca_sparse_table.cpp +++ b/tests/3-tree/test_lca_sparse_table.cpp @@ -39,8 +39,8 @@ void t_rnd() { vector> adj(n + 1); for (int v = 2; v <= n; v++) { par[v] = rnd(1, v - 1); - adj[v].push_back(par[v]); - adj[par[v]].push_back(v); + adj[v].pb(par[v]); + adj[par[v]].pb(v); } lca_sparse l; l.init(n); diff --git a/tests/3-tree/test_tree_composition.cpp b/tests/3-tree/test_tree_composition.cpp index 4baacff..389bd2f 100644 --- a/tests/3-tree/test_tree_composition.cpp +++ b/tests/3-tree/test_tree_composition.cpp @@ -12,8 +12,8 @@ int rnd(int l, int r) { } void add_edge(vector> &adj, int u, int v) { - adj[u].push_back(v); - adj[v].push_back(u); + adj[u].pb(v); + adj[v].pb(u); } vector> gen_tree(int n) { @@ -64,7 +64,7 @@ vector lca_closure(vector vs, const vector &par, const vector> &adj, const vector &vs) { st.pop_back(); for (int to : tc.vt_adj[v]) { vis[to] = 1; - st.push_back(to); + st.pb(to); } } for (int v : exp_nodes) assert(vis[v]); @@ -170,7 +170,7 @@ void t_rnd() { auto adj = gen_tree(n); int k = rnd(0, n); vector vs; - for (int i = 0; i < k; i++) vs.push_back(rnd(1, n)); + for (int i = 0; i < k; i++) vs.pb(rnd(1, n)); check_one(adj, vs); } } diff --git a/tests/3-tree/test_tree_exchange_argument.cpp b/tests/3-tree/test_tree_exchange_argument.cpp index 6a877eb..798e991 100644 --- a/tests/3-tree/test_tree_exchange_argument.cpp +++ b/tests/3-tree/test_tree_exchange_argument.cpp @@ -12,8 +12,8 @@ int rnd(int l, int r) { } void add_edge(vector> &adj, int u, int v) { - adj[u].push_back(v); - adj[v].push_back(u); + adj[u].pb(v); + adj[v].pb(u); } vector> gen_tree(int n) { @@ -35,7 +35,7 @@ vector> get_child(int n, const vector> &adj, int root) { if (to == par[v]) continue; if (par[to] != -1) continue; par[to] = v; - ch[v].push_back(to); + ch[v].pb(to); q.push(to); } } @@ -49,7 +49,7 @@ ll brute_max(int n, const vector> &ch, const vector &w, const ve for (int to : ch[v]) indeg[to]++; vector avail; for (int v = 1; v <= n; v++) - if (!indeg[v]) avail.push_back(v); + if (!indeg[v]) avail.pb(v); ll best = -(1LL << 62); vector ord; @@ -62,7 +62,7 @@ ll brute_max(int n, const vector> &ch, const vector &w, const ve } for (int i = 0; i < sz(av); i++) { int v = av[i]; - ord.push_back(v); + ord.pb(v); vector id2 = id; vector av2 = av; av2.erase(av2.begin() + i); @@ -70,7 +70,7 @@ ll brute_max(int n, const vector> &ch, const vector &w, const ve ll cost2 = cost + w[v] * tm2; for (int to : ch[v]) { id2[to]--; - if (!id2[to]) av2.push_back(to); + if (!id2[to]) av2.pb(to); } dfs(id2, av2, tm2, cost2); ord.pop_back(); diff --git a/tests/4-optimizations/test_flow.cpp b/tests/4-optimizations/test_flow.cpp index cb2732c..d0f4942 100644 --- a/tests/4-optimizations/test_flow.cpp +++ b/tests/4-optimizations/test_flow.cpp @@ -25,8 +25,8 @@ struct ek_flow { void add_edge(int u, int v, ll cap) { edge a{v, (int)g[v].size(), cap}; edge b{u, (int)g[u].size(), 0}; - g[u].push_back(a); - g[v].push_back(b); + g[u].pb(a); + g[v].pb(b); } ll max_flow(int s, int t) { if (s == t) return 0; @@ -90,8 +90,8 @@ struct mcmf_spfa { void add_edge(int u, int v, ll cap, ll cost) { edge a{v, (int)g[v].size(), cap, cost}; edge b{u, (int)g[u].size(), 0, -cost}; - g[u].push_back(a); - g[v].push_back(b); + g[u].pb(a); + g[v].pb(b); } pll min_cost_mf(int s, int t, ll max_f) { const ll INF = (1LL << 62); @@ -210,7 +210,7 @@ void t_hk() { vector> g(n_l); for (int l = 0; l < n_l; l++) for (int r = 0; r < n_r; r++) - if (rnd(0, 1)) bm.add_edge(l, r), g[l].push_back(r); + if (rnd(0, 1)) bm.add_edge(l, r), g[l].pb(r); assert(bm.max_matching() == brute_match(n_l, n_r, g)); } } @@ -229,7 +229,7 @@ void t_mcmf() { ll cap = rnd(0, 3); ll cost = rnd(-5, 5); nonneg &= (cost >= 0); - es.push_back({u, v, cap, cost}); + es.pb({u, v, cap, cost}); } mcmf mf1(n), mf2(n); mcmf_spfa na; @@ -260,7 +260,7 @@ void t_lr_dinic() { if (u == v) continue; int lo = rnd(0, 2); int hi = lo + rnd(0, 2); - es.push_back({u, v, lo, hi, 0}); + es.pb({u, v, lo, hi, 0}); f.add_edge(u, v, lo, hi); } auto exp = brute_lr(n, s, t, es); @@ -285,7 +285,7 @@ void t_lr_mcmf() { int lo = rnd(0, 2); int hi = lo + rnd(0, 2); int c = rnd(0, 5); - es.push_back({u, v, lo, hi, c}); + es.pb({u, v, lo, hi, c}); f.add_edge(u, v, lo, hi, c); } auto exp = brute_lr(n, s, t, es); diff --git a/tests/5-string/test_aho_corasick.cpp b/tests/5-string/test_aho_corasick.cpp index 96c243b..7b80c01 100644 --- a/tests/5-string/test_aho_corasick.cpp +++ b/tests/5-string/test_aho_corasick.cpp @@ -12,7 +12,7 @@ int rnd(int l, int r) { } string rnd_s(int n) { string s; - for (int i = 0; i < n; i++) s.push_back('a' + rnd(0, 2)); + for (int i = 0; i < n; i++) s.pb('a' + rnd(0, 2)); return s; } @@ -41,7 +41,7 @@ void t_rnd() { aho_corasick ac; for (int i = 0; i < n; i++) { string p = rnd_s(rnd(1, 6)); - ps.push_back(p); + ps.pb(p); ac.add(p); } ac.build(); diff --git a/tests/5-string/test_kmp_algorithm.cpp b/tests/5-string/test_kmp_algorithm.cpp index 9cb328e..dd98755 100644 --- a/tests/5-string/test_kmp_algorithm.cpp +++ b/tests/5-string/test_kmp_algorithm.cpp @@ -12,7 +12,7 @@ int rnd(int l, int r) { } string rnd_s(int n) { string s; - for (int i = 0; i < n; i++) s.push_back('a' + rnd(0, 2)); + for (int i = 0; i < n; i++) s.pb('a' + rnd(0, 2)); return s; } @@ -20,7 +20,7 @@ vector na_match(const string &t, const string &p) { vector res; if (p.empty()) return res; for (int i = 0; i + sz(p) <= sz(t); i++) - if (!t.compare(i, sz(p), p)) res.push_back(i); + if (!t.compare(i, sz(p), p)) res.pb(i); return res; } diff --git a/tests/5-string/test_manachers_algorithm.cpp b/tests/5-string/test_manachers_algorithm.cpp index 83a44bf..0d51ac9 100644 --- a/tests/5-string/test_manachers_algorithm.cpp +++ b/tests/5-string/test_manachers_algorithm.cpp @@ -12,7 +12,7 @@ int rnd(int l, int r) { } string rnd_s(int n) { string s; - for (int i = 0; i < n; i++) s.push_back('a' + rnd(0, 2)); + for (int i = 0; i < n; i++) s.pb('a' + rnd(0, 2)); return s; } diff --git a/tests/5-string/test_rabin_karp_algorithm.cpp b/tests/5-string/test_rabin_karp_algorithm.cpp index e50f849..24b9ffb 100644 --- a/tests/5-string/test_rabin_karp_algorithm.cpp +++ b/tests/5-string/test_rabin_karp_algorithm.cpp @@ -12,7 +12,7 @@ int rnd(int l, int r) { } string rnd_s(int n) { string s; - for (int i = 0; i < n; i++) s.push_back('a' + rnd(0, 2)); + for (int i = 0; i < n; i++) s.pb('a' + rnd(0, 2)); return s; } @@ -20,7 +20,7 @@ vector na_match(const string &t, const string &p) { vector res; if (p.empty()) return res; for (int i = 0; i + sz(p) <= sz(t); i++) - if (!t.compare(i, sz(p), p)) res.push_back(i); + if (!t.compare(i, sz(p), p)) res.pb(i); return res; } diff --git a/tests/5-string/test_suffix_array.cpp b/tests/5-string/test_suffix_array.cpp index d96bcfb..2f016bd 100644 --- a/tests/5-string/test_suffix_array.cpp +++ b/tests/5-string/test_suffix_array.cpp @@ -12,7 +12,7 @@ int rnd(int l, int r) { } string rnd_s(int n) { string s; - for (int i = 0; i < n; i++) s.push_back('a' + rnd(0, 2)); + for (int i = 0; i < n; i++) s.pb('a' + rnd(0, 2)); return s; } diff --git a/tests/5-string/test_trie.cpp b/tests/5-string/test_trie.cpp index 8dd9184..1673435 100644 --- a/tests/5-string/test_trie.cpp +++ b/tests/5-string/test_trie.cpp @@ -12,7 +12,7 @@ int rnd(int l, int r) { } string rnd_s(int n) { string s; - for (int i = 0; i < n; i++) s.push_back('a' + rnd(0, 2)); + for (int i = 0; i < n; i++) s.pb('a' + rnd(0, 2)); return s; } diff --git a/tests/5-string/test_z_algorithm.cpp b/tests/5-string/test_z_algorithm.cpp index 23a855c..a24cf95 100644 --- a/tests/5-string/test_z_algorithm.cpp +++ b/tests/5-string/test_z_algorithm.cpp @@ -12,7 +12,7 @@ int rnd(int l, int r) { } string rnd_s(int n) { string s; - for (int i = 0; i < n; i++) s.push_back('a' + rnd(0, 2)); + for (int i = 0; i < n; i++) s.pb('a' + rnd(0, 2)); return s; } diff --git a/tests/6-geometry/test_bulldozer_trick.cpp b/tests/6-geometry/test_bulldozer_trick.cpp index 489ba3a..4e4f499 100644 --- a/tests/6-geometry/test_bulldozer_trick.cpp +++ b/tests/6-geometry/test_bulldozer_trick.cpp @@ -15,7 +15,7 @@ vector uniq_ang(vector v) { sort(all(v)); vector u; for (auto &x : v) { - if (u.empty() || fabsl(u.back() - x) > 1e-12) u.push_back(x); + if (u.empty() || fabsl(u.back() - x) > 1e-12) u.pb(x); } return u; } @@ -23,7 +23,7 @@ vector uniq_ang(vector v) { vector perm(const vector &p, map &id) { vector res; res.reserve(sz(p)); - for (auto &v : p) res.push_back(id[{v.x, v.y}]); + for (auto &v : p) res.pb(id[{v.x, v.y}]); return res; } @@ -33,7 +33,7 @@ vector proj_ord(const vector &p, map &id, ld ang) { arr.reserve(sz(p)); for (auto &v : p) { ld pr = (ld)v.x * cs + (ld)v.y * sn; - arr.push_back({pr, id[{v.x, v.y}]}); + arr.pb({pr, id[{v.x, v.y}]}); } sort(all(arr), [&](auto &a, auto &b) { if (fabsl(a.fr - b.fr) > 1e-18) return a.fr < b.fr; @@ -41,7 +41,7 @@ vector proj_ord(const vector &p, map &id, ld ang) { }); vector ord; ord.reserve(sz(p)); - for (auto &x : arr) ord.push_back(x.sc); + for (auto &x : arr) ord.pb(x.sc); return ord; } @@ -55,12 +55,12 @@ void test_bulldozer_small() { pt v{rnd(-10, 10), rnd(-10, 10)}; if (id.count({v.x, v.y})) continue; id[{v.x, v.y}] = sz(pts); - pts.push_back(v); + pts.pb(v); } vector> got; vector cur = pts; - bulldozer(cur, [&](const vector &p) { got.push_back(perm(p, id)); }); + bulldozer(cur, [&](const vector &p) { got.pb(perm(p, id)); }); vector th; for (int i = 0; i < n; i++) { @@ -72,17 +72,17 @@ void test_bulldozer_small() { ld t = a + PI / 2; t = fmodl(t, PI); if (t < 0) t += PI; - th.push_back(t); + th.pb(t); } } th = uniq_ang(th); vector bnd; - bnd.push_back(0); + bnd.pb(0); for (auto &t : th) { - if (t > 1e-12 && t < PI - 1e-12) bnd.push_back(t); + if (t > 1e-12 && t < PI - 1e-12) bnd.pb(t); } - bnd.push_back(PI); + bnd.pb(PI); bnd = uniq_ang(bnd); vector> exp; @@ -90,7 +90,7 @@ void test_bulldozer_small() { sort(all(st)); for (int i = 0; i + 1 < sz(bnd); i++) { ld mid = (bnd[i] + bnd[i + 1]) / 2; - exp.push_back(proj_ord(st, id, mid)); + exp.pb(proj_ord(st, id, mid)); } assert(got == exp); } diff --git a/tests/6-geometry/test_convex_hull.cpp b/tests/6-geometry/test_convex_hull.cpp index 4232600..62199b8 100644 --- a/tests/6-geometry/test_convex_hull.cpp +++ b/tests/6-geometry/test_convex_hull.cpp @@ -37,7 +37,7 @@ vector jarvis(vector p) { vector h; int cur = st; while (1) { - h.push_back(p[cur]); + h.pb(p[cur]); int nxt = (cur == 0 ? 1 : 0); for (int i = 0; i < n; i++) if (i != cur) { @@ -92,7 +92,7 @@ void test_hull_random() { int n = (int)rnd(1, 50); vector p; p.reserve(n); - for (int i = 0; i < n; i++) p.push_back({rnd(-20, 20), rnd(-20, 20)}); + for (int i = 0; i < n; i++) p.pb({rnd(-20, 20), rnd(-20, 20)}); auto h1 = convex_hull(p); auto h2 = jarvis(p); auto s1 = uniq_pts(h1); diff --git a/tests/6-geometry/test_half_plane_intersection.cpp b/tests/6-geometry/test_half_plane_intersection.cpp index 3a66732..979bda8 100644 --- a/tests/6-geometry/test_half_plane_intersection.cpp +++ b/tests/6-geometry/test_half_plane_intersection.cpp @@ -27,10 +27,10 @@ bool in_hp(const hp_line &l, const ptd &p) { void test_hpi_square() { vector ln; - ln.push_back({{0, 1}, {0, 0}}); // x >= 0 - ln.push_back({{1, 0}, {1, 1}}); // x <= 1 - ln.push_back({{0, 0}, {1, 0}}); // y >= 0 - ln.push_back({{1, 1}, {0, 1}}); // y <= 1 + ln.pb({{0, 1}, {0, 0}}); // x >= 0 + ln.pb({{1, 0}, {1, 1}}); // x <= 1 + ln.pb({{0, 0}, {1, 0}}); // y >= 0 + ln.pb({{1, 1}, {0, 1}}); // y <= 1 auto poly = hpi(ln); assert(sz(poly) == 4); assert(fabsl(area_poly(poly) - 1.0L) < 1e-7); @@ -41,9 +41,9 @@ void test_hpi_square() { void test_hpi_triangle() { vector ln; - ln.push_back({{0, 1}, {0, 0}}); // x >= 0 - ln.push_back({{0, 0}, {1, 0}}); // y >= 0 - ln.push_back({{1, 0}, {0, 1}}); // x + y <= 1 + ln.pb({{0, 1}, {0, 0}}); // x >= 0 + ln.pb({{0, 0}, {1, 0}}); // y >= 0 + ln.pb({{1, 0}, {0, 1}}); // x + y <= 1 auto poly = hpi(ln); assert(sz(poly) == 3); assert(fabsl(area_poly(poly) - 0.5L) < 1e-7); @@ -54,8 +54,8 @@ void test_hpi_triangle() { void test_hpi_empty() { vector ln; - ln.push_back({{0, 1}, {0, 0}}); // x >= 0 - ln.push_back({{-1, 0}, {-1, 1}}); // x <= -1 + ln.pb({{0, 1}, {0, 0}}); // x >= 0 + ln.pb({{-1, 0}, {-1, 1}}); // x <= -1 auto poly = hpi(ln); assert(poly.empty()); } @@ -65,15 +65,15 @@ void test_hpi_random_convex() { int n = (int)rnd(10, 30); vector p; p.reserve(n); - for (int i = 0; i < n; i++) p.push_back({rnd(-20, 20), rnd(-20, 20)}); + for (int i = 0; i < n; i++) p.pb({rnd(-20, 20), rnd(-20, 20)}); auto h = convex_hull(p); if (sz(h) < 3) continue; vector hp; - for (auto &v : h) hp.push_back({(ld)v.x, (ld)v.y}); + for (auto &v : h) hp.pb({(ld)v.x, (ld)v.y}); vector ln; for (int i = 0; i < sz(hp); i++) { - ln.push_back({hp[i], hp[(i + 1) % sz(hp)]}); + ln.pb({hp[i], hp[(i + 1) % sz(hp)]}); } auto poly = hpi(ln); assert(sz(poly) == sz(hp)); diff --git a/tests/6-geometry/test_minimum_enclosing_circle.cpp b/tests/6-geometry/test_minimum_enclosing_circle.cpp index e4e8110..eaefbfa 100644 --- a/tests/6-geometry/test_minimum_enclosing_circle.cpp +++ b/tests/6-geometry/test_minimum_enclosing_circle.cpp @@ -89,7 +89,7 @@ void test_mec_random_brute() { p.reserve(n); for (int i = 0; i < n; i++) { ptd v{(ld)rnd(-5, 5), (ld)rnd(-5, 5)}; - p.push_back(v); + p.pb(v); } auto got = min_circle(p); auto exp = brute_mec(p); diff --git a/tests/6-geometry/test_ray_casting.cpp b/tests/6-geometry/test_ray_casting.cpp index 0e959ad..19fd397 100644 --- a/tests/6-geometry/test_ray_casting.cpp +++ b/tests/6-geometry/test_ray_casting.cpp @@ -43,7 +43,7 @@ void test_in_poly_random_convex() { int n = (int)rnd(3, 40); vector p; p.reserve(n); - for (int i = 0; i < n; i++) p.push_back({rnd(-20, 20), rnd(-20, 20)}); + for (int i = 0; i < n; i++) p.pb({rnd(-20, 20), rnd(-20, 20)}); auto h = convex_hull(p); if (sz(h) < 3) continue; diff --git a/tests/6-geometry/test_rotating_callipers.cpp b/tests/6-geometry/test_rotating_callipers.cpp index 6bee9b2..e81555c 100644 --- a/tests/6-geometry/test_rotating_callipers.cpp +++ b/tests/6-geometry/test_rotating_callipers.cpp @@ -34,7 +34,7 @@ void test_diam_random() { int n = (int)rnd(1, 50); vector p; p.reserve(n); - for (int i = 0; i < n; i++) p.push_back({rnd(-30, 30), rnd(-30, 30)}); + for (int i = 0; i < n; i++) p.pb({rnd(-30, 30), rnd(-30, 30)}); auto h = convex_hull(p); if (sz(h) == 0) continue; auto res = hull_diam(h); diff --git a/tests/6-geometry/test_segment_intersection.cpp b/tests/6-geometry/test_segment_intersection.cpp index 1279ae6..1c5a7c3 100644 --- a/tests/6-geometry/test_segment_intersection.cpp +++ b/tests/6-geometry/test_segment_intersection.cpp @@ -17,8 +17,8 @@ pt rnd_pt(ll l, ll r) { bool on_seg_ld(const pt &a, const pt &b, const ptd &p) { ptd pa{(ld)a.x, (ld)a.y}; - ptd pb{(ld)b.x, (ld)b.y}; - ptd ab = pb - pa; + ptd p_b{(ld)b.x, (ld)b.y}; + ptd ab = p_b - pa; ptd ap = p - pa; if (fabsl(cross(ab, ap)) > 1e-8) return 0; ld lx = min((ld)a.x, (ld)b.x) - 1e-8; diff --git a/tests/6-geometry/test_sort_by_angular.cpp b/tests/6-geometry/test_sort_by_angular.cpp index 263b811..7a8e361 100644 --- a/tests/6-geometry/test_sort_by_angular.cpp +++ b/tests/6-geometry/test_sort_by_angular.cpp @@ -45,7 +45,7 @@ void test_sort_ang_random() { pt a = u - o, b = v - o; if (cross(a, b) == 0) ok = 0; } - if (ok) p.push_back(v); + if (ok) p.pb(v); } assert(sz(p) == n); diff --git a/tests/7-math/test_misc_sqrt.cpp b/tests/7-math/test_misc_sqrt.cpp index 5304da1..bd51083 100644 --- a/tests/7-math/test_misc_sqrt.cpp +++ b/tests/7-math/test_misc_sqrt.cpp @@ -21,7 +21,7 @@ bool is_prime_ref(ll x) { vector div_ref(ll x) { vector d; for (ll i = 1; i <= x; i++) - if (x % i == 0) d.push_back(i); + if (x % i == 0) d.pb(i); return d; } @@ -29,11 +29,11 @@ vector fac_ref(ll x) { vector p; for (ll i = 2; i <= x / i; i++) { while (x % i == 0) { - p.push_back(i); + p.pb(i); x /= i; } } - if (x > 1) p.push_back(x); + if (x > 1) p.pb(x); return p; } diff --git a/tests/7-math/test_nt_crt.cpp b/tests/7-math/test_nt_crt.cpp index 2c45e14..ab2fe5e 100644 --- a/tests/7-math/test_nt_crt.cpp +++ b/tests/7-math/test_nt_crt.cpp @@ -57,7 +57,7 @@ void test_merge_all() { for (int i = 0; i < k; i++) { ll m = rnd(1, 30); ll r = rnd(-30, 30); - cs.push_back({r, m}); + cs.pb({r, m}); } pll ans = crt::merge_all(cs); ll brute = brute_crt(cs); diff --git a/tests/7-math/test_nt_mr_rho.cpp b/tests/7-math/test_nt_mr_rho.cpp index 510210f..d4f95f6 100644 --- a/tests/7-math/test_nt_mr_rho.cpp +++ b/tests/7-math/test_nt_mr_rho.cpp @@ -22,11 +22,11 @@ vector fac_ref(ll x) { vector f; for (ll p = 2; p * p <= x; p++) { while (x % p == 0) { - f.push_back(p); + f.pb(p); x /= p; } } - if (x > 1) f.push_back(x); + if (x > 1) f.pb(x); sort(all(f)); return f; } diff --git a/tests/7-math/test_nt_sieve.cpp b/tests/7-math/test_nt_sieve.cpp index 5661cf1..ba0704c 100644 --- a/tests/7-math/test_nt_sieve.cpp +++ b/tests/7-math/test_nt_sieve.cpp @@ -49,8 +49,8 @@ vector divisors(int x) { vector d; for (int i = 1; 1LL * i * i <= x; i++) { if (x % i) continue; - d.push_back(i); - if (i * i != x) d.push_back(x / i); + d.pb(i); + if (i * i != x) d.pb(x / i); } return d; } diff --git a/tests/8-misc/test_kitamasa.cpp b/tests/8-misc/test_kitamasa.cpp index 88fc9c4..99e832d 100644 --- a/tests/8-misc/test_kitamasa.cpp +++ b/tests/8-misc/test_kitamasa.cpp @@ -20,7 +20,7 @@ ll naive_rec(const vector &coef, const vector &init, ll n, ll mod) { for (int j = 1; j <= k; j++) { v = mod_norm(v + (__int128)coef[j - 1] * a[i - j], mod); } - a.push_back(v); + a.pb(v); } return a[n]; } diff --git a/tests/8-misc/test_system_of_difference_constraints.cpp b/tests/8-misc/test_system_of_difference_constraints.cpp index d536a65..0173ed9 100644 --- a/tests/8-misc/test_system_of_difference_constraints.cpp +++ b/tests/8-misc/test_system_of_difference_constraints.cpp @@ -42,7 +42,7 @@ void test_random() { int v = rnd_int(0, n - 1); ll w = rnd_int(-5, 5); dc.add_le(u, v, w); - edges.push_back({u, v, w}); + edges.pb({u, v, w}); } bool ok = dc.solve(); bool neg = has_neg_cycle(n, edges); From 7bcb0654c5582985c9d5552043413f2c23095020 Mon Sep 17 00:00:00 2001 From: manoflearning <77jwk0724@gmail.com> Date: Sun, 4 Jan 2026 02:11:31 +0900 Subject: [PATCH 2/6] chore: apply sz, all, rall --- src/1-ds/erasable_pq.cpp | 2 +- src/2-graph/offline_dynamic_connectivity.cpp | 2 +- src/4-optimizations/flow.cpp | 28 +++++++++---------- src/8-misc/dp_opt.cpp | 2 +- src/8-misc/lis_in_o_nlogn.cpp | 4 +-- .../sqrt_decomposition_mos_algorithm.cpp | 2 +- tests/1-ds/test_erasable_pq.cpp | 4 +-- tests/1-ds/test_pbds.cpp | 8 +++--- tests/1-ds/test_segment_tree.cpp | 6 ++-- tests/2-graph/test_bcc.cpp | 2 +- tests/4-optimizations/test_flow.cpp | 8 +++--- tests/7-math/test_conv_fft.cpp | 4 +-- tests/8-misc/test_fraction_data_type.cpp | 10 +++---- .../test_sqrt_decomposition_mos_algorithm.cpp | 6 ++-- 14 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/1-ds/erasable_pq.cpp b/src/1-ds/erasable_pq.cpp index a450e9d..10f972e 100644 --- a/src/1-ds/erasable_pq.cpp +++ b/src/1-ds/erasable_pq.cpp @@ -7,7 +7,7 @@ template > struct erase_pq { priority_queue, cmp> q, del; - int size() { return (int)q.size() - (int)del.size(); } + int size() { return sz(q) - sz(del); } bool empty() { return size() == 0; } const T &top() { return (fix(), q.top()); } // result: current extreme element. void push(const T &x) { q.push(x); } diff --git a/src/2-graph/offline_dynamic_connectivity.cpp b/src/2-graph/offline_dynamic_connectivity.cpp index 465d6dc..d16c7ab 100644 --- a/src/2-graph/offline_dynamic_connectivity.cpp +++ b/src/2-graph/offline_dynamic_connectivity.cpp @@ -84,7 +84,7 @@ struct dyn_conn { } else if (op == 2) { auto it = mp.find({u, v}); if (it == mp.end()) return; - sg.add(it->second, i - 1, {u, v}); + sg.add(it->sc, i - 1, {u, v}); mp.erase(it); } else if (op == 3) { qry[i] = {u, v}; diff --git a/src/4-optimizations/flow.cpp b/src/4-optimizations/flow.cpp index 38b26cd..9ec4e38 100644 --- a/src/4-optimizations/flow.cpp +++ b/src/4-optimizations/flow.cpp @@ -34,11 +34,11 @@ struct dinic { edge_ref add_edge(int u, int v, ll cap) { // goal: add forward + reverse edge - edge a{v, (int)g[v].size(), cap}; - edge b{u, (int)g[u].size(), 0}; + edge a{v, sz(g[v]), cap}; + edge b{u, sz(g[u]), 0}; g[u].pb(a); g[v].pb(b); - return {u, (int)g[u].size() - 1}; + return {u, sz(g[u]) - 1}; } ll edge_flow(edge_ref e) const { @@ -75,7 +75,7 @@ struct dinic { ll dfs(int v, int t, ll f) { if (v == t || f == 0) return f; - for (int &i = work[v]; i < (int)g[v].size(); i++) { + for (int &i = work[v]; i < sz(g[v]); i++) { edge &e = g[v][i]; if (e.cap == 0 || level[e.to] != level[v] + 1) continue; // invariant: level strictly increases along augmenting path @@ -132,7 +132,7 @@ struct hk { bool bfs() { // goal: build layers for shortest augmenting paths queue q; - fill(dist.begin(), dist.end(), -1); + fill(all(dist), -1); for (int i = 0; i < n_l; i++) { if (match_l[i] == -1) { dist[i] = 0; @@ -171,8 +171,8 @@ struct hk { int max_matching() { // goal: compute maximum matching size - fill(match_l.begin(), match_l.end(), -1); - fill(match_r.begin(), match_r.end(), -1); + fill(all(match_l), -1); + fill(all(match_r), -1); int match = 0; while (bfs()) { for (int i = 0; i < n_l; i++) { @@ -212,11 +212,11 @@ struct mcmf { edge_ref add_edge(int u, int v, ll cap, ll cost) { // goal: add forward + reverse edge with costs - edge a{v, (int)g[v].size(), cap, cost}; - edge b{u, (int)g[u].size(), 0, -cost}; + edge a{v, sz(g[v]), cap, cost}; + edge b{u, sz(g[u]), 0, -cost}; g[u].pb(a); g[v].pb(b); - return {u, (int)g[u].size() - 1}; + return {u, sz(g[u]) - 1}; } ll edge_flow(edge_ref e) const { @@ -267,7 +267,7 @@ struct mcmf { while (flow < max_f) { // goal: shortest path in reduced costs - fill(dist.begin(), dist.end(), INF); + fill(all(dist), INF); dist[s] = 0; priority_queue, vector>, greater>> pq; pq.push({0, s}); @@ -275,7 +275,7 @@ struct mcmf { auto [d, v] = pq.top(); pq.pop(); if (d != dist[v]) continue; - for (int i = 0; i < (int)g[v].size(); i++) { + for (int i = 0; i < sz(g[v]); i++) { const auto &e = g[v][i]; if (e.cap == 0) continue; ll nd = d + e.cost + pot[v] - pot[e.to]; @@ -341,7 +341,7 @@ struct lr_dinic { demand[u] -= lo; demand[v] += lo; edges.pb({mf.add_edge(u, v, hi - lo), lo}); - return (int)edges.size() - 1; + return sz(edges) - 1; } ll edge_flow(int id) const { @@ -430,7 +430,7 @@ struct lr_mcmf { demand[v] += lo; base_cost += lo * cost; edges.pb({mf.add_edge(u, v, hi - lo, cost), lo}); - return (int)edges.size() - 1; + return sz(edges) - 1; } ll edge_flow(int id) const { diff --git a/src/8-misc/dp_opt.cpp b/src/8-misc/dp_opt.cpp index bf806a5..fdb80ef 100644 --- a/src/8-misc/dp_opt.cpp +++ b/src/8-misc/dp_opt.cpp @@ -104,7 +104,7 @@ struct dnc_opt { prv = base; cur.assign(n, INF); for (int g = 1; g <= k; g++) { - fill(cur.begin(), cur.end(), INF); + fill(all(cur), INF); solve(0, n - 1, 0, n - 1, cost); prv.swap(cur); } diff --git a/src/8-misc/lis_in_o_nlogn.cpp b/src/8-misc/lis_in_o_nlogn.cpp index 6b0f1db..126350d 100644 --- a/src/8-misc/lis_in_o_nlogn.cpp +++ b/src/8-misc/lis_in_o_nlogn.cpp @@ -9,7 +9,7 @@ int lis_len(const vector &a) { // result: length of LIS. vector tail; for (ll x : a) { - auto it = lower_bound(tail.begin(), tail.end(), x); + auto it = lower_bound(all(tail), x); if (it == tail.end()) tail.pb(x); else *it = x; } @@ -24,7 +24,7 @@ vector lis_seq(const vector &a) { vector pre(n, -1); for (int i = 0; i < n; i++) { ll x = a[i]; - int pos = lower_bound(tail.begin(), tail.end(), x) - tail.begin(); + int pos = lower_bound(all(tail), x) - tail.begin(); if (pos == sz(tail)) { tail.pb(x); tail_idx.pb(i); diff --git a/src/8-misc/sqrt_decomposition_mos_algorithm.cpp b/src/8-misc/sqrt_decomposition_mos_algorithm.cpp index 4e1de81..684f55c 100644 --- a/src/8-misc/sqrt_decomposition_mos_algorithm.cpp +++ b/src/8-misc/sqrt_decomposition_mos_algorithm.cpp @@ -26,7 +26,7 @@ struct mo { template void run(Add add, Del del, Out out) { // goal: process queries in Mo order with callbacks. - sort(q.begin(), q.end(), [&](const qry &a, const qry &b) { + sort(all(q), [&](const qry &a, const qry &b) { int ba = a.l / bs, bb = b.l / bs; if (ba != bb) return ba < bb; return (ba & 1) ? a.r > b.r : a.r < b.r; diff --git a/tests/1-ds/test_erasable_pq.cpp b/tests/1-ds/test_erasable_pq.cpp index 9336e72..0f26519 100644 --- a/tests/1-ds/test_erasable_pq.cpp +++ b/tests/1-ds/test_erasable_pq.cpp @@ -12,7 +12,7 @@ ll rnd(ll l, ll r) { } ll pick_multiset(multiset &ms) { - int idx = (int)rnd(0, (int)ms.size() - 1); + int idx = (int)rnd(0, sz(ms) - 1); auto it = ms.begin(); advance(it, idx); return *it; @@ -59,7 +59,7 @@ void test_randomized() { } else { assert(pq.top() == *prev(ms.end())); } - assert(pq.size() == (int)ms.size()); + assert(pq.size() == sz(ms)); if (ms.empty()) { assert(pq.empty()); } else { diff --git a/tests/1-ds/test_pbds.cpp b/tests/1-ds/test_pbds.cpp index 6dae4b4..558574b 100644 --- a/tests/1-ds/test_pbds.cpp +++ b/tests/1-ds/test_pbds.cpp @@ -45,14 +45,14 @@ void test_oset_random() { st.insert(x); } else if (op == 1) { if (st.empty()) continue; - ll x = kth_set(st, (int)rnd(0, (ll)st.size() - 1)); + ll x = kth_set(st, (int)rnd(0, sz(st) - 1)); s.erase(x); st.erase(x); } else { ll x = rnd(-10, 10); assert((int)s.order_of_key(x) == (int)distance(st.begin(), st.lower_bound(x))); if (!st.empty()) { - int k = (int)rnd(0, (ll)st.size() - 1); + int k = (int)rnd(0, sz(st) - 1); assert(*s.find_by_order(k) == kth_set(st, k)); } } @@ -83,14 +83,14 @@ void test_omset_random() { ms.insert(x); } else if (op == 1) { if (ms.empty()) continue; - ll x = kth_multiset(ms, (int)rnd(0, (ll)ms.size() - 1)); + ll x = kth_multiset(ms, (int)rnd(0, sz(ms) - 1)); m_erase(s, x); ms.erase(ms.find(x)); } else { ll x = rnd(-5, 5); assert(m_order(s, x) == (int)distance(ms.begin(), ms.lower_bound(x))); if (!ms.empty()) { - int k = (int)rnd(0, (ll)ms.size() - 1); + int k = (int)rnd(0, sz(ms) - 1); assert(m_kth(s, k) == kth_multiset(ms, k)); } } diff --git a/tests/1-ds/test_segment_tree.cpp b/tests/1-ds/test_segment_tree.cpp index 1cda5a1..b564e35 100644 --- a/tests/1-ds/test_segment_tree.cpp +++ b/tests/1-ds/test_segment_tree.cpp @@ -188,7 +188,7 @@ void test_pst_random() { ver.pb(nw); st.set(p, v); } else { - int id = (int)rnd(0, (int)ver.size() - 1); + int id = (int)rnd(0, sz(ver) - 1); int l = (int)rnd(1, n); int r = (int)rnd(l, n); assert(st.query(l, r, id) == sum_range(ver[id], l, r)); @@ -232,7 +232,7 @@ void test_pst_kth_random() { ver.pb(nw); st.set(p, v); } else { - int id = (int)rnd(0, (int)ver.size() - 1); + int id = (int)rnd(0, sz(ver) - 1); ll tot = 0; for (int i = 1; i <= n; i++) tot += ver[id][i]; if (tot == 0) continue; @@ -270,7 +270,7 @@ void test_dyseg_random() { int r = (int)rnd(l, hi); ll ret = 0; for (auto &kv : mp) - if (l <= kv.first && kv.first <= r) ret += kv.second; + if (l <= kv.fr && kv.fr <= r) ret += kv.sc; assert(st.query(l, r) == ret); } } diff --git a/tests/2-graph/test_bcc.cpp b/tests/2-graph/test_bcc.cpp index 5508f79..35b34df 100644 --- a/tests/2-graph/test_bcc.cpp +++ b/tests/2-graph/test_bcc.cpp @@ -78,7 +78,7 @@ void chk_bcc(int n, const vector &ed, bcc_graph &g) { for (auto &comp : g.bccs) { if (sz(comp) <= 1) continue; - vector>> adj(n + 1); + vector> adj(n + 1); for (int i = 0; i < sz(comp); i++) { int u = comp[i].fr, v = comp[i].sc; adj[u].pb({v, i}); diff --git a/tests/4-optimizations/test_flow.cpp b/tests/4-optimizations/test_flow.cpp index d0f4942..89c8bbe 100644 --- a/tests/4-optimizations/test_flow.cpp +++ b/tests/4-optimizations/test_flow.cpp @@ -23,8 +23,8 @@ struct ek_flow { g.assign(n, {}); } void add_edge(int u, int v, ll cap) { - edge a{v, (int)g[v].size(), cap}; - edge b{u, (int)g[u].size(), 0}; + edge a{v, sz(g[v]), cap}; + edge b{u, sz(g[u]), 0}; g[u].pb(a); g[v].pb(b); } @@ -88,8 +88,8 @@ struct mcmf_spfa { g.assign(n, {}); } void add_edge(int u, int v, ll cap, ll cost) { - edge a{v, (int)g[v].size(), cap, cost}; - edge b{u, (int)g[u].size(), 0, -cost}; + edge a{v, sz(g[v]), cap, cost}; + edge b{u, sz(g[u]), 0, -cost}; g[u].pb(a); g[v].pb(b); } diff --git a/tests/7-math/test_conv_fft.cpp b/tests/7-math/test_conv_fft.cpp index b9eab85..543bdea 100644 --- a/tests/7-math/test_conv_fft.cpp +++ b/tests/7-math/test_conv_fft.cpp @@ -85,7 +85,7 @@ void test_ntt() { for (int i = 0; i < m; i++) b[i] = rnd_int(0, mod - 1); auto ref = conv_mod_ref(a, b, mod); auto got = ntt_conv::mul(a, b); - assert(got.size() == ref.size()); + assert(sz(got) == sz(ref)); for (int i = 0; i < sz(ref); i++) assert(got[i] == ref[i]); } } @@ -100,7 +100,7 @@ void test_ntt_any() { for (int i = 0; i < m; i++) b[i] = rnd_int(0, 1000); auto ref = conv_mod_ref(a, b, mod); auto got = ntt_any::mul(a, b, mod); - assert(got.size() == ref.size()); + assert(sz(got) == sz(ref)); for (int i = 0; i < sz(ref); i++) assert(got[i] == ref[i]); } } diff --git a/tests/8-misc/test_fraction_data_type.cpp b/tests/8-misc/test_fraction_data_type.cpp index 08eb17f..4ab72b0 100644 --- a/tests/8-misc/test_fraction_data_type.cpp +++ b/tests/8-misc/test_fraction_data_type.cpp @@ -11,7 +11,7 @@ ll rnd(ll l, ll r) { return dis(rng); } -pair norm_pair(ll n, ll d) { +pll norm_pair(ll n, ll d) { if (d < 0) n = -n, d = -d; ll g = fraction::gcd_ll(n, d); if (g) n /= g, d /= g; @@ -48,10 +48,10 @@ void test_ops_random() { fraction xsub = x - y; fraction xmul = x * y; fraction xdiv = x / y; - assert(xadd.n == add.first && xadd.d == add.second); - assert(xsub.n == sub.first && xsub.d == sub.second); - assert(xmul.n == mul.first && xmul.d == mul.second); - assert(xdiv.n == div.first && xdiv.d == div.second); + assert(xadd.n == add.fr && xadd.d == add.sc); + assert(xsub.n == sub.fr && xsub.d == sub.sc); + assert(xmul.n == mul.fr && xmul.d == mul.sc); + assert(xdiv.n == div.fr && xdiv.d == div.sc); bool lt = (__int128)xn * yd < (__int128)yn * xd; assert((x < y) == lt); } diff --git a/tests/8-misc/test_sqrt_decomposition_mos_algorithm.cpp b/tests/8-misc/test_sqrt_decomposition_mos_algorithm.cpp index 7abc58d..022118a 100644 --- a/tests/8-misc/test_sqrt_decomposition_mos_algorithm.cpp +++ b/tests/8-misc/test_sqrt_decomposition_mos_algorithm.cpp @@ -16,7 +16,7 @@ void test_distinct() { vector a(n); for (int i = 0; i < n; i++) a[i] = rnd_int(0, 30); - vector> qs(qn); + vector qs(qn); for (int i = 0; i < qn; i++) { int l = rnd_int(0, n - 1); int r = rnd_int(l, n - 1); @@ -27,14 +27,14 @@ void test_distinct() { for (int i = 0; i < qn; i++) { vector cnt(31, 0); int cur = 0; - for (int j = qs[i].first; j <= qs[i].second; j++) { + for (int j = qs[i].fr; j <= qs[i].sc; j++) { if (cnt[a[j]]++ == 0) cur++; } naive[i] = cur; } mo solver(n); - for (int i = 0; i < qn; i++) solver.add_query(qs[i].first, qs[i].second, i); + for (int i = 0; i < qn; i++) solver.add_query(qs[i].fr, qs[i].sc, i); vector cnt(31, 0); int cur = 0; From 42caa12dac997c03a70c26c3d3821b97e57ba339 Mon Sep 17 00:00:00 2001 From: manoflearning <77jwk0724@gmail.com> Date: Sun, 4 Jan 2026 02:42:20 +0900 Subject: [PATCH 3/6] remove --- src/common/common.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/common/common.hpp b/src/common/common.hpp index 5e8de73..9b740d9 100644 --- a/src/common/common.hpp +++ b/src/common/common.hpp @@ -4,7 +4,6 @@ using namespace std; using ll = long long; using ld = long double; -using ull = unsigned long long; using pii = pair; using pll = pair; #define fr first @@ -12,4 +11,3 @@ using pll = pair; #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() -#define rall(x) (x).rbegin(), (x).rend() From f4ba79cf42c5e06ba5ee0ade27b287859c9ec118 Mon Sep 17 00:00:00 2001 From: manoflearning <77jwk0724@gmail.com> Date: Sun, 4 Jan 2026 02:49:45 +0900 Subject: [PATCH 4/6] vi vl vvi vvl --- src/1-ds/fenwick_tree.cpp | 16 +++---- src/1-ds/merge_sort_tree.cpp | 8 ++-- src/1-ds/segment_tree.cpp | 30 ++++++------- src/1-ds/union_find.cpp | 2 +- src/2-graph/bcc.cpp | 2 +- src/2-graph/euler_circuit.cpp | 12 ++--- src/2-graph/kth_shortest_path.cpp | 10 ++--- src/2-graph/offline_dynamic_connectivity.cpp | 4 +- src/2-graph/scc_2_sat.cpp | 12 ++--- src/2-graph/shortest_path.cpp | 10 ++--- src/3-tree/centroid_decomp.cpp | 4 +- src/3-tree/hld.cpp | 6 +-- src/3-tree/lca_sparse_table.cpp | 6 +-- src/3-tree/tree_composition.cpp | 10 ++--- src/3-tree/tree_exchange_argument.cpp | 8 ++-- src/4-optimizations/flow.cpp | 16 +++---- src/4-optimizations/hungarian.cpp | 10 ++--- src/5-string/aho_corasick.cpp | 2 +- src/5-string/kmp_algorithm.cpp | 8 ++-- src/5-string/manachers_algorithm.cpp | 4 +- src/5-string/rabin_karp_algorithm.cpp | 6 +-- src/5-string/suffix_array.cpp | 10 ++--- src/5-string/z_algorithm.cpp | 4 +- src/6-geometry/bulldozer_trick.cpp | 4 +- src/7-math/comb_binom.cpp | 6 +-- src/7-math/comb_cat_der.cpp | 2 +- src/7-math/conv_fft.cpp | 22 +++++----- src/7-math/linalg_gauss.cpp | 12 ++--- src/7-math/linalg_mat.cpp | 4 +- src/7-math/misc_sqrt.cpp | 8 ++-- src/7-math/nt_mr_rho.cpp | 6 +-- src/7-math/nt_sieve.cpp | 12 ++--- src/8-misc/dp_opt.cpp | 16 +++---- src/8-misc/kitamasa.cpp | 4 +- src/8-misc/lis_in_o_nlogn.cpp | 14 +++--- .../system_of_difference_constraints.cpp | 4 +- src/common/common.hpp | 4 ++ tests/1-ds/test_fenwick_tree.cpp | 16 +++---- tests/1-ds/test_merge_sort_tree.cpp | 10 ++--- tests/1-ds/test_segment_tree.cpp | 44 +++++++++---------- tests/1-ds/test_union_find.cpp | 4 +- tests/2-graph/test_bcc.cpp | 12 ++--- tests/2-graph/test_euler_circuit.cpp | 20 ++++----- tests/2-graph/test_kth_shortest_path.cpp | 6 +-- .../test_offline_dynamic_connectivity.cpp | 8 ++-- tests/2-graph/test_scc_2_sat.cpp | 14 +++--- tests/2-graph/test_shortest_path.cpp | 6 +-- tests/3-tree/test_centroid_decomp.cpp | 34 +++++++------- tests/3-tree/test_hld.cpp | 16 +++---- tests/3-tree/test_lca_sparse_table.cpp | 8 ++-- tests/3-tree/test_tree_composition.cpp | 28 ++++++------ tests/3-tree/test_tree_exchange_argument.cpp | 38 ++++++++-------- tests/4-optimizations/test_flow.cpp | 16 +++---- tests/4-optimizations/test_hungarian.cpp | 10 ++--- tests/5-string/test_kmp_algorithm.cpp | 8 ++-- tests/5-string/test_rabin_karp_algorithm.cpp | 4 +- tests/5-string/test_suffix_array.cpp | 4 +- tests/5-string/test_z_algorithm.cpp | 4 +- tests/6-geometry/test_bulldozer_trick.cpp | 12 ++--- tests/7-math/test_comb_cat_der.cpp | 8 ++-- tests/7-math/test_conv_fft.cpp | 22 +++++----- tests/7-math/test_linalg_gauss.cpp | 10 ++--- tests/7-math/test_linalg_mat.cpp | 4 +- tests/7-math/test_misc_sqrt.cpp | 14 +++--- tests/7-math/test_nt_mr_rho.cpp | 12 ++--- tests/7-math/test_nt_sieve.cpp | 4 +- tests/8-misc/test_dp_opt.cpp | 20 ++++----- tests/8-misc/test_kitamasa.cpp | 6 +-- tests/8-misc/test_lis_in_o_nlogn.cpp | 12 ++--- tests/8-misc/test_simd.cpp | 2 +- .../test_sqrt_decomposition_mos_algorithm.cpp | 8 ++-- .../test_system_of_difference_constraints.cpp | 4 +- 72 files changed, 385 insertions(+), 381 deletions(-) diff --git a/src/1-ds/fenwick_tree.cpp b/src/1-ds/fenwick_tree.cpp index 6b5fa2b..cbdf86a 100644 --- a/src/1-ds/fenwick_tree.cpp +++ b/src/1-ds/fenwick_tree.cpp @@ -6,14 +6,14 @@ // usage: fenwick fw; fw.build(a); fw.add(p, x); fw.sum(l, r); fw.kth(k); struct fenwick { int n; - vector a, t; + vl a, t; void init(int n_) { // goal: allocate arrays for size n. n = n_; a.assign(n, 0); t.assign(n, 0); } - void build(const vector &v) { + void build(const vl &v) { // goal: build fenwick in O(n) from initial array. n = sz(v); a = v; @@ -60,7 +60,7 @@ struct fenwick { // 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; + vl t; void init(int n_) { // goal: allocate internal tree (1-indexed). n = n_; @@ -85,19 +85,19 @@ struct fenw_range { // 1-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; + vvl a, t; void init(int n_, int m_) { // goal: allocate arrays for n x m. n = n_, m = m_; - a.assign(n, vector(m, 0)); - t.assign(n, vector(m, 0)); + a.assign(n, vl(m, 0)); + t.assign(n, vl(m, 0)); } - void build(const vector> &v) { + void build(const vvl &v) { // goal: build 2D fenwick in O(n*m). n = sz(v); m = n ? sz(v[0]) : 0; a = v; - t.assign(n, vector(m, 0)); + t.assign(n, vl(m, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { t[i][j] += a[i][j]; diff --git a/src/1-ds/merge_sort_tree.cpp b/src/1-ds/merge_sort_tree.cpp index 50b5b70..2f9f3b7 100644 --- a/src/1-ds/merge_sort_tree.cpp +++ b/src/1-ds/merge_sort_tree.cpp @@ -6,8 +6,8 @@ constexpr int MAX_MST = 1 << 17; // constraint: MAX_MST >= n; values fit in int; 0-indexed [l, r]; build once. // 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) { + vi t[MAX_MST << 1]; + void build(const vi &a) { // goal: build sorted lists for each node. for (int i = 0; i < sz(a); i++) t[i + MAX_MST].pb(a[i]); @@ -31,8 +31,8 @@ struct merge_seg { // constraint: MAX_MST >= n; values fit in int; 0-indexed [l, r]; build once. // 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) { + vi t[MAX_MST << 1]; + void build(const vi &a) { // goal: build sorted lists for each node. for (int i = 0; i < sz(a); i++) t[i + MAX_MST].pb(a[i]); diff --git a/src/1-ds/segment_tree.cpp b/src/1-ds/segment_tree.cpp index 6f595d6..06d0775 100644 --- a/src/1-ds/segment_tree.cpp +++ b/src/1-ds/segment_tree.cpp @@ -6,8 +6,8 @@ // 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) { + vl t; + void build(const vl &a) { // goal: build tree from 1-indexed array. int n = sz(a) - 1; flag = 1; @@ -36,8 +36,8 @@ struct seg_tree { // 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) { + vl t; + void build(const vl &a) { // goal: build tree from 0-indexed array. n = sz(a); t.assign(2 * n, 0); @@ -65,7 +65,7 @@ struct seg_tree_it { // 0-indexed // usage: seg_tree_kth st; st.init(n); st.add(p, v); st.kth(k); struct seg_tree_kth { int flag; - vector t; + vl t; void init(int n) { // goal: allocate tree for size n. flag = 1; @@ -91,8 +91,8 @@ struct seg_tree_kth { // 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) { + vl t, lz; + void build(const vl &a) { // goal: build tree and clear lazy tags. int n = sz(a) - 1; flag = 1; @@ -149,10 +149,10 @@ struct seg_pst { }; int n; vector t; - vector root; + vi root; void newnd() { t.pb({-1, -1, 0}); } - void build(int n_, const vector &a) { + void build(int n_, const vl &a) { // goal: build initial version. n = n_; t.clear(); @@ -161,7 +161,7 @@ struct seg_pst { root.pb(0); build(1, n, root[0], a); } - void build(int l, int r, int v, const vector &a) { + void build(int l, int r, int v, const vl &a) { // goal: build node v for range [l, r]. if (l == r) { t[v].val = a[l]; @@ -275,11 +275,11 @@ struct seg_sparse { // 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) { + vvl t; + void build(const vvl &a) { // goal: build 2D tree from initial grid. n = sz(a); - t.assign(2 * n, vector(2 * n, 0)); + t.assign(2 * n, vl(2 * n, 0)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) t[i + n][j + n] = a[i][j]; @@ -325,8 +325,8 @@ struct seg_2d { // 0-indexed // 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; + vvl a; + vvi used; unordered_map mp; seg2d_comp(int n) : n(n), a(2 * n), used(2 * n) {} void mark_set(int x, int y) { diff --git a/src/1-ds/union_find.cpp b/src/1-ds/union_find.cpp index 9412ccf..e8355bc 100644 --- a/src/1-ds/union_find.cpp +++ b/src/1-ds/union_find.cpp @@ -5,7 +5,7 @@ // constraint: 1-indexed [1, n]. // usage: dsu d; d.init(n); d.join(a, b); int r = d.find(x); int s = d.size(x); struct dsu { - vector p; + vi p; void init(int n) { p.assign(n + 1, -1); } // goal: reset to n singletons. int find(int x) { return p[x] < 0 ? x : p[x] = find(p[x]); } // result: root of x. int size(int x) { return -p[find(x)]; } diff --git a/src/2-graph/bcc.cpp b/src/2-graph/bcc.cpp index c59257d..c7ce283 100644 --- a/src/2-graph/bcc.cpp +++ b/src/2-graph/bcc.cpp @@ -7,7 +7,7 @@ struct bcc_graph { int n, tim; vector> adj; - vector dfn, low, ap, st; + vi dfn, low, ap, st; vector ed, ae; vector> bccs; diff --git a/src/2-graph/euler_circuit.cpp b/src/2-graph/euler_circuit.cpp index 265e431..7552b2f 100644 --- a/src/2-graph/euler_circuit.cpp +++ b/src/2-graph/euler_circuit.cpp @@ -6,13 +6,13 @@ // 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; + vvi adj; + vi nxt, path; void init(int n_) { // goal: allocate adjacency matrix and reset state. n = n_; - adj.assign(n + 1, vector(n + 1)); + adj.assign(n + 1, vi(n + 1)); nxt.assign(n + 1, 1); path.clear(); } @@ -23,7 +23,7 @@ struct euler_cir { } bool can() { // result: whether an Euler circuit exists. - vector deg(n + 1); + vi deg(n + 1); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) deg[i] += adj[i][j]; for (int i = 1; i <= n; i++) @@ -35,7 +35,7 @@ struct euler_cir { break; } if (!s) return 1; - vector vis(n + 1); + vi vis(n + 1); queue q; q.push(s); vis[s] = 1; @@ -60,7 +60,7 @@ struct euler_cir { } path.pb(v); } - vector run(int s = 1) { + vi run(int s = 1) { // result: Euler circuit starting from s (if exists). for (int i = 1; i <= n; i++) nxt[i] = 1; path.clear(); diff --git a/src/2-graph/kth_shortest_path.cpp b/src/2-graph/kth_shortest_path.cpp index c86093a..4986635 100644 --- a/src/2-graph/kth_shortest_path.cpp +++ b/src/2-graph/kth_shortest_path.cpp @@ -47,9 +47,9 @@ struct kth_walk { rg[v].pb({w, u}); } - vector run(int s, int e, int k) { - vector nxt(n + 1, -1), ord, vis(n + 1); - vector dist(n + 1, INF); + vl run(int s, int e, int k) { + vi nxt(n + 1, -1), ord, vis(n + 1); + vl dist(n + 1, INF); // goal: shortest path tree from e on reversed graph. dist[e] = 0; @@ -72,7 +72,7 @@ struct kth_walk { } if (dist[s] >= INF) return {}; - vector rt(n + 1), chk(n + 1); + vi rt(n + 1), chk(n + 1); for (int x : ord) if (dist[x] < INF) { if (nxt[x] != -1) rt[x] = rt[nxt[x]]; @@ -86,7 +86,7 @@ struct kth_walk { } } - vector ans = {dist[s]}; + vl ans = {dist[s]}; priority_queue, greater> pq2; if (rt[s]) pq2.push({hp.h[rt[s]].x.fr, rt[s]}); while (sz(ans) < k && !pq2.empty()) { diff --git a/src/2-graph/offline_dynamic_connectivity.cpp b/src/2-graph/offline_dynamic_connectivity.cpp index d16c7ab..a875c73 100644 --- a/src/2-graph/offline_dynamic_connectivity.cpp +++ b/src/2-graph/offline_dynamic_connectivity.cpp @@ -28,7 +28,7 @@ struct dyn_conn { } sg; struct dsu { - vector par, siz, st; + vi par, siz, st; void init(int n) { // goal: reset to n isolated nodes. par.resize(n + 1); @@ -64,7 +64,7 @@ struct dyn_conn { int n, q; map mp; vector qry; - vector ans; + vi ans; void init(int n_, int q_) { // goal: initialize with n nodes and q operations. diff --git a/src/2-graph/scc_2_sat.cpp b/src/2-graph/scc_2_sat.cpp index 88a3a4f..bf0e64d 100644 --- a/src/2-graph/scc_2_sat.cpp +++ b/src/2-graph/scc_2_sat.cpp @@ -6,8 +6,8 @@ // 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; + vvi g, rg, sccs; + vi vis, comp, ord; void init(int n_) { n = n_; @@ -53,8 +53,8 @@ struct scc_kosa { // 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; + vvi g, sccs; + vi dfn, low, comp, st, ins; void init(int n_) { n = n_; @@ -105,8 +105,8 @@ struct scc_tarjan { // usage: two_sat s; s.init(n); s.add(a,b); bool ok=s.run(); // s.val struct two_sat { int n, tim, cid; - vector> g; - vector dfn, low, comp, st, ins, val; + vvi g; + vi dfn, low, comp, st, ins, val; void init(int n_) { n = n_; diff --git a/src/2-graph/shortest_path.cpp b/src/2-graph/shortest_path.cpp index 3dfc933..c929df3 100644 --- a/src/2-graph/shortest_path.cpp +++ b/src/2-graph/shortest_path.cpp @@ -15,9 +15,9 @@ struct dijkstra { adj.assign(n + 1, {}); } void add(int u, int v, ll w) { adj[u].pb({w, v}); } - vector run(int s) { + vl run(int s) { // result: dist[i] = shortest distance from s to i. - vector dist(n + 1, INF); + vl dist(n + 1, INF); priority_queue, greater> pq; dist[s] = 0; pq.push({0, s}); @@ -51,7 +51,7 @@ struct bell_ford { ed.clear(); } void add(int u, int v, ll w) { ed.pb({u, v, w}); } - bool run(int s, vector &dist) { + bool run(int s, vl &dist) { // result: false if a negative cycle is reachable. dist.assign(n + 1, INF); dist[s] = 0; @@ -78,12 +78,12 @@ struct bell_ford { struct floyd { static const ll INF = (1LL << 62); int n; - vector> d; + vvl d; void init(int n_) { // goal: initialize distance matrix. n = n_; - d.assign(n + 1, vector(n + 1, INF)); + d.assign(n + 1, vl(n + 1, INF)); for (int i = 1; i <= n; i++) d[i][i] = 0; } void add(int u, int v, ll w) { d[u][v] = min(d[u][v], w); } diff --git a/src/3-tree/centroid_decomp.cpp b/src/3-tree/centroid_decomp.cpp index 8837a41..c58f79b 100644 --- a/src/3-tree/centroid_decomp.cpp +++ b/src/3-tree/centroid_decomp.cpp @@ -6,8 +6,8 @@ // usage: cen_decomp cd; cd.init(n); cd.add(u,v); cd.build(); int p=cd.par[v]; struct cen_decomp { int n; - vector> adj, chd; - vector par, siz; + vvi adj, chd; + vi par, siz; vector used; void init(int n_) { diff --git a/src/3-tree/hld.cpp b/src/3-tree/hld.cpp index d02bf92..fdb16b5 100644 --- a/src/3-tree/hld.cpp +++ b/src/3-tree/hld.cpp @@ -8,8 +8,8 @@ struct hld_tree { seg_tree seg; int n, tim; - vector> adj; - vector par, dep, siz, heavy, top, in; + vvi adj; + vi par, dep, siz, heavy, top, in; void init(int n_) { n = n_; @@ -51,7 +51,7 @@ struct hld_tree { void build(int root = 1) { dfs_sz(root, 0); dfs_hld(root, root); - vector a(n + 1, 0); + vl a(n + 1, 0); seg.build(a); } void set(int v, ll val) { seg.set(in[v], val); } diff --git a/src/3-tree/lca_sparse_table.cpp b/src/3-tree/lca_sparse_table.cpp index 17a415a..f9ebd7c 100644 --- a/src/3-tree/lca_sparse_table.cpp +++ b/src/3-tree/lca_sparse_table.cpp @@ -6,15 +6,15 @@ // usage: lca_sparse l; l.init(n); l.add(u,v); l.build(1); int w=l.lca(u,v); struct lca_sparse { int n, lg; - vector> adj, up; - vector dep; + vvi adj, up; + vi dep; void init(int n_) { n = n_; lg = 1; while ((1 << lg) <= n) lg++; adj.assign(n + 1, {}); - up.assign(lg, vector(n + 1, 0)); + up.assign(lg, vi(n + 1, 0)); dep.assign(n + 1, 0); } void add(int u, int v) { diff --git a/src/3-tree/tree_composition.cpp b/src/3-tree/tree_composition.cpp index 88ea68a..b599728 100644 --- a/src/3-tree/tree_composition.cpp +++ b/src/3-tree/tree_composition.cpp @@ -6,15 +6,15 @@ // usage: tree_comp tc; tc.init(n); tc.add(u,v); tc.build(root); auto nodes=tc.make(vs); // use tc.vt_adj struct tree_comp { int n, lg, tim; - vector> adj, up, vt_adj; - vector tin, tout, dep; + vvi adj, up, vt_adj; + vi tin, tout, dep; void init(int n_) { n = n_; lg = 1; while ((1 << lg) <= n) lg++; adj.assign(n + 1, {}); - up.assign(lg, vector(n + 1, 0)); + up.assign(lg, vi(n + 1, 0)); vt_adj.assign(n + 1, {}); tin.assign(n + 1, 0); tout.assign(n + 1, 0); @@ -57,7 +57,7 @@ struct tree_comp { } return up[0][a]; } - vector make(vector vs) { + vi make(vi vs) { if (vs.empty()) return {}; sort(all(vs), [&](int a, int b) { return tin[a] < tin[b]; }); vs.erase(unique(all(vs)), vs.end()); @@ -66,7 +66,7 @@ struct tree_comp { sort(all(vs), [&](int a, int b) { return tin[a] < tin[b]; }); vs.erase(unique(all(vs)), vs.end()); for (int v : vs) vt_adj[v].clear(); - vector st; + vi st; st.pb(vs[0]); for (int i = 1; i < sz(vs); i++) { int v = vs[i]; diff --git a/src/3-tree/tree_exchange_argument.cpp b/src/3-tree/tree_exchange_argument.cpp index d0ab5c6..005f6c3 100644 --- a/src/3-tree/tree_exchange_argument.cpp +++ b/src/3-tree/tree_exchange_argument.cpp @@ -6,8 +6,8 @@ // usage: tree_xchg tx; tx.init(n, root); tx.add(u,v); // set tx.ds.w/t/cw; ll ans=tx.run(); struct tree_xchg { struct uf { - vector par; - vector cw, w, t; + vi par; + vl cw, w, t; void init(int n) { par.assign(n + 1, -1); cw.resize(n + 1); @@ -32,8 +32,8 @@ struct tree_xchg { }; int n, root; - vector> adj; - vector par; + vvi adj; + vi par; void init(int n_, int r) { n = n_; diff --git a/src/4-optimizations/flow.cpp b/src/4-optimizations/flow.cpp index 9ec4e38..09ee0c9 100644 --- a/src/4-optimizations/flow.cpp +++ b/src/4-optimizations/flow.cpp @@ -23,7 +23,7 @@ struct dinic { int n; vector> g; - vector level, work; + vi level, work; dinic(int n = 0) { init(n); } @@ -110,8 +110,8 @@ struct dinic { // usage: hk bm(n_l, n_r); bm.add_edge(l, r); int m = bm.max_matching(); struct hk { int n_l, n_r; - vector> g; - vector dist, match_l, match_r; + vvi g; + vi dist, match_l, match_r; hk(int n_l_ = 0, int n_r_ = 0) { init(n_l_, n_r_); } @@ -235,12 +235,12 @@ struct mcmf { pll min_cost_mf(int s, int t, ll max_f = INF, bool init_pot = true) { ll flow = 0, cost = 0; - vector pot(n, 0), dist(n); - vector pv(n), pe(n); + vl pot(n, 0), dist(n); + vi pv(n), pe(n); if (init_pot) { // goal: initial potentials for negative costs - vector d(n, INF); + vl d(n, INF); vector in_q(n, 0); queue q; d[s] = 0; @@ -324,7 +324,7 @@ struct lr_dinic { int n; dinic mf; - vector demand; + vl demand; vector edges; lr_dinic(int n = 0) { init(n); } @@ -410,7 +410,7 @@ struct lr_mcmf { int n; mcmf mf; - vector demand; + vl demand; vector edges; ll base_cost; diff --git a/src/4-optimizations/hungarian.cpp b/src/4-optimizations/hungarian.cpp index 2ab6b01..2339241 100644 --- a/src/4-optimizations/hungarian.cpp +++ b/src/4-optimizations/hungarian.cpp @@ -5,15 +5,15 @@ // constraint: 1 <= n <= m, 1-indexed cost a[1..n][1..m] (minimization). // usage: hungarian hu; auto [cost, match_l] = hu.run(n, m, a); // match_l[i]=j struct hungarian { - pair> run(int n, int m, const vector> &a) { + pair run(int n, int m, const vvl &a) { // result: {min_cost, match_l} with match_l[i]=assigned column. const ll INF = (1LL << 62); - vector u(n + 1), v(m + 1); - vector p(m + 1), way(m + 1); + vl u(n + 1), v(m + 1); + vi p(m + 1), way(m + 1); for (int i = 1; i <= n; i++) { p[0] = i; int j0 = 0; - vector minv(m + 1, INF); + vl minv(m + 1, INF); vector used(m + 1, 0); do { used[j0] = 1; @@ -41,7 +41,7 @@ struct hungarian { j0 = j1; } while (j0); } - vector match_l(n + 1, 0); + vi match_l(n + 1, 0); for (int j = 1; j <= m; j++) if (p[j]) match_l[p[j]] = j; return {-v[0], match_l}; diff --git a/src/5-string/aho_corasick.cpp b/src/5-string/aho_corasick.cpp index f21cbf6..6e28bd5 100644 --- a/src/5-string/aho_corasick.cpp +++ b/src/5-string/aho_corasick.cpp @@ -7,7 +7,7 @@ struct aho_corasick { static constexpr int ALPHA = 26; vector> nxt; - vector fail, out; + vi fail, out; aho_corasick() { init(); } diff --git a/src/5-string/kmp_algorithm.cpp b/src/5-string/kmp_algorithm.cpp index 5c32e49..ad167d3 100644 --- a/src/5-string/kmp_algorithm.cpp +++ b/src/5-string/kmp_algorithm.cpp @@ -4,9 +4,9 @@ // time: O(|t|+|p|); memory: O(|p|) // constraint: returns 0-indexed match positions. // usage: auto pos = kmp_match(t, p); // p in t -vector kmp_pi(const string &p) { +vi kmp_pi(const string &p) { // result: pi[i] = length of longest proper prefix ending at i. - vector pi(sz(p)); + vi pi(sz(p)); for (int i = 1, j = 0; i < sz(p); i++) { while (j && p[i] != p[j]) j = pi[j - 1]; if (p[i] == p[j]) pi[i] = ++j; @@ -14,9 +14,9 @@ vector kmp_pi(const string &p) { return pi; } -vector kmp_match(const string &t, const string &p) { +vi kmp_match(const string &t, const string &p) { // result: all start indices where p matches t. - vector res; + vi res; if (p.empty()) return res; auto pi = kmp_pi(p); for (int i = 0, j = 0; i < sz(t); i++) { diff --git a/src/5-string/manachers_algorithm.cpp b/src/5-string/manachers_algorithm.cpp index 65c6a1f..d728426 100644 --- a/src/5-string/manachers_algorithm.cpp +++ b/src/5-string/manachers_algorithm.cpp @@ -4,10 +4,10 @@ // time: O(n); memory: O(n) // constraint: 0-indexed; d1[i]=odd radius, d2[i]=even radius. // usage: auto [d1,d2]=manacher(s); // max len = max(2*d1[i]-1,2*d2[i]) -pair, vector> manacher(const string &s) { +pair manacher(const string &s) { // result: d1/d2 radii for odd/even palindromes centered at i. int n = sz(s); - vector d1(n), d2(n); + vi d1(n), d2(n); for (int i = 0, l = 0, r = -1; i < n; i++) { int k = (i > r) ? 1 : min(d1[l + r - i], r - i + 1); while (i - k >= 0 && i + k < n && s[i - k] == s[i + k]) k++; diff --git a/src/5-string/rabin_karp_algorithm.cpp b/src/5-string/rabin_karp_algorithm.cpp index 5ea0b87..66974ed 100644 --- a/src/5-string/rabin_karp_algorithm.cpp +++ b/src/5-string/rabin_karp_algorithm.cpp @@ -8,7 +8,7 @@ struct rabin_karp { static constexpr ll MOD1 = 1000000007; static constexpr ll MOD2 = 1000000009; static constexpr ll BASE = 911382323; - vector p1, p2, h1, h2; + vl p1, p2, h1, h2; void build(const string &s) { // goal: precompute prefix hashes and powers. @@ -36,9 +36,9 @@ struct rabin_karp { } }; -vector rk_match(const string &t, const string &p) { +vi rk_match(const string &t, const string &p) { // result: all positions where p matches t (by hash). - vector res; + vi res; int n = sz(t), m = sz(p); if (!m || n < m) return res; rabin_karp ht, hp; diff --git a/src/5-string/suffix_array.cpp b/src/5-string/suffix_array.cpp index e77f29a..10257f5 100644 --- a/src/5-string/suffix_array.cpp +++ b/src/5-string/suffix_array.cpp @@ -4,12 +4,12 @@ // time: build_sa O(n log n), build_lcp O(n); memory: O(n) // constraint: s is 0-indexed string, sa is 0-indexed positions. // usage: suffix_array sa; sa.build(s); // sa.sa, sa.lcp (lcp[i]=lcp(sa[i], sa[i-1])) -vector build_sa(const string &s) { +vi build_sa(const string &s) { // result: sa[i] = starting index of i-th suffix in sorted order. int n = sz(s); if (!n) return {}; int m = max(256, n) + 1; - vector sa(n), r(2 * n), nr(2 * n), cnt(m), idx(n); + vi sa(n), r(2 * n), nr(2 * n), cnt(m), idx(n); for (int i = 0; i < n; i++) sa[i] = i, r[i] = (unsigned char)s[i]; for (int d = 1; d < n; d <<= 1) { auto cmp = [&](int i, int j) { @@ -32,10 +32,10 @@ vector build_sa(const string &s) { return sa; } -vector build_lcp(const string &s, const vector &sa) { +vi build_lcp(const string &s, const vi &sa) { // result: lcp[i] = LCP of sa[i] and sa[i-1]. int n = sz(s); - vector lcp(n), rk(n); + vi lcp(n), rk(n); for (int i = 0; i < n; i++) rk[sa[i]] = i; for (int i = 0, k = 0; i < n; i++) { int r = rk[i]; @@ -49,7 +49,7 @@ vector build_lcp(const string &s, const vector &sa) { } struct suffix_array { - vector sa, lcp; + vi sa, lcp; void build(const string &s) { // goal: fill sa and lcp for string s. sa = build_sa(s); diff --git a/src/5-string/z_algorithm.cpp b/src/5-string/z_algorithm.cpp index 917c31d..7ae1048 100644 --- a/src/5-string/z_algorithm.cpp +++ b/src/5-string/z_algorithm.cpp @@ -4,10 +4,10 @@ // time: O(n); memory: O(n) // constraint: z[0]=n, 0-indexed string. // usage: auto z = z_func(s); -vector z_func(const string &s) { +vi z_func(const string &s) { // result: z[i] = longest prefix length matching s[i..]. int n = sz(s); - vector z(n); + vi z(n); if (!n) return z; z[0] = n; for (int i = 1, l = 0, r = 0; i < n; i++) { diff --git a/src/6-geometry/bulldozer_trick.cpp b/src/6-geometry/bulldozer_trick.cpp index ad66628..8f5c335 100644 --- a/src/6-geometry/bulldozer_trick.cpp +++ b/src/6-geometry/bulldozer_trick.cpp @@ -22,7 +22,7 @@ void bulldozer(vector &p, F f) { int n = sz(p); sort(all(p)); vector base = p; - vector pos(n); + vi pos(n); iota(all(pos), 0); vector ln; ln.reserve(1LL * n * (n - 1) / 2); @@ -44,7 +44,7 @@ void bulldozer(vector &p, F f) { while (j < sz(ln) && ln[j] == ln[i]) j++; ll dx = ln[i].dx, dy = ln[i].dy; if (dx == 0) break; - unordered_map> mp; + unordered_map mp; mp.reserve((j - i) * 2 + 1); for (int k = i; k < j; k++) { int u = ln[k].u, v = ln[k].v; diff --git a/src/7-math/comb_binom.cpp b/src/7-math/comb_binom.cpp index dcaa9b6..18add67 100644 --- a/src/7-math/comb_binom.cpp +++ b/src/7-math/comb_binom.cpp @@ -23,12 +23,12 @@ struct comb_lr { // usage: comb_dp cb; cb.init(n); ll v=cb.ncr(n,r); struct comb_dp { int n; - vector> dp; + vvl dp; void init(int n_) { // goal: build dp up to n. n = n_; - dp.assign(n + 1, vector(n + 1, 0)); + dp.assign(n + 1, vl(n + 1, 0)); for (int i = 0; i <= n; i++) { dp[i][0] = dp[i][i] = 1; for (int j = 1; j < i; j++) dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]; @@ -48,7 +48,7 @@ struct comb_dp { struct comb_mod { int n; ll mod; - vector fac, ifac; + vl fac, ifac; void init(int n_, ll mod_) { // goal: precompute fac/ifac up to n. diff --git a/src/7-math/comb_cat_der.cpp b/src/7-math/comb_cat_der.cpp index e22a421..d6b49a9 100644 --- a/src/7-math/comb_cat_der.cpp +++ b/src/7-math/comb_cat_der.cpp @@ -28,7 +28,7 @@ struct catalan_mod { // usage: derange_mod de; de.init(n, mod); ll v=de.get(k); struct derange_mod { ll mod; - vector dp; + vl dp; void init(int n, ll mod_) { // goal: precompute derangements up to n. diff --git a/src/7-math/conv_fft.cpp b/src/7-math/conv_fft.cpp index 28c4418..4f6434e 100644 --- a/src/7-math/conv_fft.cpp +++ b/src/7-math/conv_fft.cpp @@ -35,7 +35,7 @@ struct fft_conv { for (int i = 0; i < n; i++) a[i] /= n; } - static vector mul(const vector &a, const vector &b) { + static vl mul(const vl &a, const vl &b) { // result: integer convolution of a and b. if (a.empty() || b.empty()) return {}; int n = 1; @@ -47,12 +47,12 @@ struct fft_conv { fft(fb); for (int i = 0; i < n; i++) fa[i] *= fb[i]; fft(fa, 1); - vector ret(n); + vl ret(n); for (int i = 0; i < n; i++) ret[i] = llround(fa[i].real()); return ret; } - static vector mul_mod(const vector &a, const vector &b, ll mod) { + static vl mul_mod(const vl &a, const vl &b, ll mod) { // result: convolution of a and b modulo mod. if (a.empty() || b.empty()) return {}; int n = 1; @@ -73,7 +73,7 @@ struct fft_conv { } fft(r1, 1); fft(r2, 1); - vector ret(n); + vl ret(n); for (int i = 0; i < n; i++) { ll av = llround(r1[i].real()) % mod; ll bv = (llround(r1[i].imag()) + llround(r2[i].real())) % mod; @@ -111,16 +111,16 @@ struct ntt_mod { return ans; } - static void ntt(vector &a) { + static void ntt(vl &a) { // goal: inplace NTT of a. int n = sz(a), lg = 31 - __builtin_clz(n); - static vector rt(2, 1); + static vl rt(2, 1); for (static int k = 2, s = 2; k < n; k <<= 1, s++) { rt.resize(n); ll z[] = {1, mod_pow(ROOT, MOD >> s)}; for (int i = k; i < 2 * k; i++) rt[i] = rt[i / 2] * z[i & 1] % MOD; } - vector rev(n); + vl rev(n); for (int i = 0; i < n; i++) rev[i] = (rev[i / 2] | (i & 1) << lg) / 2; for (int i = 0; i < n; i++) if (i < rev[i]) swap(a[i], a[rev[i]]); @@ -134,14 +134,14 @@ struct ntt_mod { } } - static vector mul(const vector &a, const vector &b) { + static vl mul(const vl &a, const vl &b) { // result: convolution under MOD. if (a.empty() || b.empty()) return {}; int s = sz(a) + sz(b) - 1; int n = 1; while (n < s) n <<= 1; int inv = mod_pow(n, MOD - 2); - vector l(n, 0), r(n, 0), out(n); + vl l(n, 0), r(n, 0), out(n); for (int i = 0; i < sz(a); i++) l[i] = norm(a[i]); for (int i = 0; i < sz(b); i++) r[i] = norm(b[i]); ntt(l); @@ -168,7 +168,7 @@ struct ntt_any { static constexpr ll M2 = 469762049; static constexpr ll M3 = 1224736769; - static vector mul(const vector &a, const vector &b, ll mod) { + static vl mul(const vl &a, const vl &b, ll mod) { // result: convolution under arbitrary mod via CRT. if (a.empty() || b.empty()) return {}; using ntt1 = ntt_mod; @@ -184,7 +184,7 @@ struct ntt_any { const ll INV_M1M2_M3 = euclid::inv_mod(M1M2 % M3, M3); int n = sz(c1); - vector ret(n); + vl ret(n); for (int i = 0; i < n; i++) { ll x1 = c1[i]; ll x2 = c2[i] - x1; diff --git a/src/7-math/linalg_gauss.cpp b/src/7-math/linalg_gauss.cpp index d8a1485..16375bd 100644 --- a/src/7-math/linalg_gauss.cpp +++ b/src/7-math/linalg_gauss.cpp @@ -46,10 +46,10 @@ struct gauss_real { // constraint: mod is prime; matrix is n x (m+1) augmented. // usage: auto x=gauss_mod::solve(a, mod); // empty if no solution struct gauss_mod { - static vector solve(vector> a, int mod) { + static vi solve(vvi a, int mod) { int n = sz(a); int m = sz(a[0]) - 1; - vector where(m, -1); + vi where(m, -1); int r = 0; for (int c = 0; c < m && r < n; c++) { int p = r; @@ -83,7 +83,7 @@ struct gauss_mod { } if (all0 && a[i][m]) return {}; } - vector ans(m, 0); + vi ans(m, 0); for (int i = 0; i < m; i++) if (where[i] != -1) ans[i] = a[where[i]][m]; return ans; @@ -95,9 +95,9 @@ struct gauss_mod { // constraint: each row is size >= m+1; last bit is RHS. // usage: auto x=gauss_xor::solve(a, m); // empty if no solution struct gauss_xor { - static vector solve(vector> a, int m) { + static vi solve(vector> a, int m) { int n = sz(a); - vector where(m, -1); + vi where(m, -1); int r = 0; for (int c = 0; c < m && r < n; c++) { int p = -1; @@ -122,7 +122,7 @@ struct gauss_xor { } if (all0 && a[i][m]) return {}; } - vector ans(m, 0); + vi ans(m, 0); for (int i = 0; i < m; i++) if (where[i] != -1) ans[i] = a[where[i]][m]; return ans; diff --git a/src/7-math/linalg_mat.cpp b/src/7-math/linalg_mat.cpp index d09bdbf..1bd446a 100644 --- a/src/7-math/linalg_mat.cpp +++ b/src/7-math/linalg_mat.cpp @@ -7,9 +7,9 @@ // usage: matrix a(n,n,mod); auto r=matrix::power(a, e); struct matrix { ll mod; - vector> a; + vvl a; - matrix(int n = 0, int m = 0, ll mod_ = 1) : mod(mod_), a(n, vector(m, 0)) {} + matrix(int n = 0, int m = 0, ll mod_ = 1) : mod(mod_), a(n, vl(m, 0)) {} static matrix ident(int n, ll mod) { matrix r(n, n, mod); diff --git a/src/7-math/misc_sqrt.cpp b/src/7-math/misc_sqrt.cpp index a6a30bf..8a96a0b 100644 --- a/src/7-math/misc_sqrt.cpp +++ b/src/7-math/misc_sqrt.cpp @@ -6,9 +6,9 @@ // constraint: x >= 1 and fits in ll. // usage: auto d=sqrt_alg::divisors(x); auto pf=sqrt_alg::prime_fac(x); struct sqrt_alg { - static vector divisors(ll x) { + static vl divisors(ll x) { // result: sorted divisors of x. - vector d; + vl d; for (ll i = 1; i <= x / i; i++) { if (x % i) continue; d.pb(i); @@ -18,9 +18,9 @@ struct sqrt_alg { return d; } - static vector prime_fac(ll x) { + static vl prime_fac(ll x) { // result: prime factors of x (with repetition). - vector p; + vl p; while ((x & 1) == 0) { p.pb(2); x >>= 1; diff --git a/src/7-math/nt_mr_rho.cpp b/src/7-math/nt_mr_rho.cpp index 76e97ac..fb00038 100644 --- a/src/7-math/nt_mr_rho.cpp +++ b/src/7-math/nt_mr_rho.cpp @@ -60,7 +60,7 @@ struct pollard_rho { } } - static void rec(ll n, vector &out) { + static void rec(ll n, vl &out) { if (n == 1) return; if (miller_rabin::is_prime(n)) { out.pb(n); @@ -71,9 +71,9 @@ struct pollard_rho { rec(n / d, out); } - static vector factor(ll n) { + static vl factor(ll n) { // result: prime factors of |n| with repetition, sorted. - vector out; + vl out; if (n < 0) n = -n; if (n == 0) return out; rec(n, out); diff --git a/src/7-math/nt_sieve.cpp b/src/7-math/nt_sieve.cpp index 8a4451b..5dc8d75 100644 --- a/src/7-math/nt_sieve.cpp +++ b/src/7-math/nt_sieve.cpp @@ -8,7 +8,7 @@ struct era_sieve { int n; vector isp; - vector primes; + vi primes; era_sieve(int n_ = 0) { if (n_ >= 0) init(n_); @@ -40,7 +40,7 @@ struct era_sieve { // usage: lin_sieve sv(n); auto fc=sv.factor_cnt(x); int mu=sv.mu[x]; struct lin_sieve { int n; - vector lp, primes, mu, phi; + vi lp, primes, mu, phi; lin_sieve(int n_ = 0) { if (n_ >= 0) init(n_); @@ -78,9 +78,9 @@ struct lin_sieve { bool is_prime(int x) const { return x >= 2 && x <= n && lp[x] == x; } - vector factor(int x) const { + vi factor(int x) const { // result: prime factors of x (with repetition), in nondecreasing order - vector ret; + vi ret; while (x > 1) { int p = lp[x]; ret.pb(p); @@ -106,7 +106,7 @@ struct lin_sieve { // time: O(n); memory: O(n) // constraint: n >= 0. // usage: auto mu = mobius(n); if(mu[x]) ... -inline vector mobius(int n) { +inline vi mobius(int n) { lin_sieve sv(n); return sv.mu; } @@ -129,7 +129,7 @@ struct euler_phi { return ret; } - static vector phi_upto(int n) { + static vi phi_upto(int n) { lin_sieve sv(n); return sv.phi; } diff --git a/src/8-misc/dp_opt.cpp b/src/8-misc/dp_opt.cpp index fdb80ef..c37dca5 100644 --- a/src/8-misc/dp_opt.cpp +++ b/src/8-misc/dp_opt.cpp @@ -59,15 +59,15 @@ struct cht_mono { struct knuth_opt { static constexpr ll INF = (1LL << 62); int n; - vector> dp; - vector> opt; + vvl dp; + vvi opt; template void build(int n_, F cost) { // goal: fill dp/opt for 0..n-1 n = n_; - dp.assign(n, vector(n, 0)); - opt.assign(n, vector(n, 0)); + dp.assign(n, vl(n, 0)); + opt.assign(n, vi(n, 0)); for (int i = 0; i < n; i++) opt[i][i] = i; for (int len = 2; len <= n; len++) { for (int i = 0; i + len - 1 < n; i++) { @@ -96,10 +96,10 @@ struct knuth_opt { // usage: dnc_opt dc; dc.run(k, n, base, cost); auto ans = dc.dp(); struct dnc_opt { static constexpr ll INF = (1LL << 62); - vector prv, cur; + vl prv, cur; template - void run(int k, int n, const vector &base, F cost) { + void run(int k, int n, const vl &base, F cost) { // goal: compute dp for k layers, starting from base prv = base; cur.assign(n, INF); @@ -110,7 +110,7 @@ struct dnc_opt { } } - const vector &dp() const { return prv; } + const vl &dp() const { return prv; } template void solve(int l, int r, int opt_l, int opt_r, F cost) { @@ -134,7 +134,7 @@ struct dnc_opt { // time: O(n log n); memory: O(n) // constraint: values fit in ll. // usage: ll ops = slope_trick(a); -ll slope_trick(vector a) { +ll slope_trick(vl a) { ll ret = 0; priority_queue pq; for (int i = 0; i < sz(a); i++) { diff --git a/src/8-misc/kitamasa.cpp b/src/8-misc/kitamasa.cpp index e6595cb..a095943 100644 --- a/src/8-misc/kitamasa.cpp +++ b/src/8-misc/kitamasa.cpp @@ -4,7 +4,7 @@ // time: O(k^2 log n); memory: O(k^2) // constraint: coef.size() == init.size(); mod >= 1. // usage: coef[i] for A_{n-1-i}; ll an = kitamasa(coef, init, n, mod); -using poly = vector; +using poly = vl; ll mod_norm(ll x, ll mod) { x %= mod; @@ -36,7 +36,7 @@ poly poly_div(const poly &a, const poly &f, ll mod) { return ret; } -ll kitamasa(const vector &coef, const vector &init, ll n, ll mod) { +ll kitamasa(const vl &coef, const vl &init, ll n, ll mod) { int k = sz(coef); assert(k == sz(init)); if (n < k) return mod_norm(init[n], mod); diff --git a/src/8-misc/lis_in_o_nlogn.cpp b/src/8-misc/lis_in_o_nlogn.cpp index 126350d..9e35eef 100644 --- a/src/8-misc/lis_in_o_nlogn.cpp +++ b/src/8-misc/lis_in_o_nlogn.cpp @@ -5,9 +5,9 @@ // constraint: use lower_bound for strict; use upper_bound for non-decreasing. // usage: int len = lis_len(a); auto seq = lis_seq(a); -int lis_len(const vector &a) { +int lis_len(const vl &a) { // result: length of LIS. - vector tail; + vl tail; for (ll x : a) { auto it = lower_bound(all(tail), x); if (it == tail.end()) tail.pb(x); @@ -16,12 +16,12 @@ int lis_len(const vector &a) { return sz(tail); } -vector lis_seq(const vector &a) { +vl lis_seq(const vl &a) { // result: one LIS sequence. int n = sz(a); - vector tail; - vector tail_idx; - vector pre(n, -1); + vl tail; + vi tail_idx; + vi pre(n, -1); for (int i = 0; i < n; i++) { ll x = a[i]; int pos = lower_bound(all(tail), x) - tail.begin(); @@ -34,7 +34,7 @@ vector lis_seq(const vector &a) { } if (pos > 0) pre[i] = tail_idx[pos - 1]; } - vector ret; + vl ret; int cur = tail_idx.empty() ? -1 : tail_idx.back(); while (cur != -1) { ret.pb(a[cur]); diff --git a/src/8-misc/system_of_difference_constraints.cpp b/src/8-misc/system_of_difference_constraints.cpp index 45c632a..3071a1e 100644 --- a/src/8-misc/system_of_difference_constraints.cpp +++ b/src/8-misc/system_of_difference_constraints.cpp @@ -12,7 +12,7 @@ struct diff_cons { int n; vector> g; - vector dist; + vl dist; diff_cons(int n_ = 0) { init(n_); } @@ -61,5 +61,5 @@ struct diff_cons { return true; } - vector val() const { return dist; } + vl val() const { return dist; } }; diff --git a/src/common/common.hpp b/src/common/common.hpp index 9b740d9..4f27a97 100644 --- a/src/common/common.hpp +++ b/src/common/common.hpp @@ -6,6 +6,10 @@ using ll = long long; using ld = long double; using pii = pair; using pll = pair; +using vi = vector; +using vl = vector; +using vvi = vector>; +using vvl = vector>; #define fr first #define sc second #define pb push_back diff --git a/tests/1-ds/test_fenwick_tree.cpp b/tests/1-ds/test_fenwick_tree.cpp index afec125..02e5c8e 100644 --- a/tests/1-ds/test_fenwick_tree.cpp +++ b/tests/1-ds/test_fenwick_tree.cpp @@ -11,13 +11,13 @@ ll rnd(ll l, ll r) { return dis(rng); } -ll sum_1d(const vector &a, int l, int r) { +ll sum_1d(const vl &a, int l, int r) { ll ret = 0; for (int i = l; i <= r; i++) ret += a[i]; return ret; } -int kth_naive(const vector &a, ll k) { +int kth_naive(const vl &a, ll k) { ll cur = 0; for (int i = 0; i < sz(a); i++) { cur += a[i]; @@ -26,7 +26,7 @@ int kth_naive(const vector &a, ll k) { return -1; } -ll sum_2d(const vector> &a, int x1, int y1, int x2, int y2) { +ll sum_2d(const vvl &a, int x1, int y1, int x2, int y2) { ll ret = 0; for (int i = x1; i <= x2; i++) for (int j = y1; j <= y2; j++) ret += a[i][j]; @@ -35,7 +35,7 @@ ll sum_2d(const vector> &a, int x1, int y1, int x2, int y2) { void test_fenwick_basic() { fenwick fw; - vector a = {5}; + vl a = {5}; fw.build(a); assert(fw.sum(0, 0) == 5); assert(fw.kth(1) == 0); @@ -47,7 +47,7 @@ void test_fenwick_basic() { void test_fenwick_random() { int n = 50; - vector a(n); + vl a(n); for (int i = 0; i < n; i++) a[i] = rnd(0, 5); fenwick fw; @@ -88,7 +88,7 @@ void test_fenwick_rp_basic() { void test_fenwick_rp_random() { int n = 40; - vector a(n + 1, 0); + vl a(n + 1, 0); fenw_range fw; fw.init(n); @@ -109,7 +109,7 @@ void test_fenwick_rp_random() { void test_fenwick_2d_basic() { fenw_2d fw; - vector> a = {{3}}; + vvl a = {{3}}; fw.build(a); assert(fw.sum(0, 0, 0, 0) == 3); fw.set(0, 0, -2); @@ -118,7 +118,7 @@ void test_fenwick_2d_basic() { void test_fenwick_2d_random() { int n = 8, m = 7; - vector> a(n, vector(m, 0)); + vvl a(n, vl(m, 0)); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = rnd(-3, 3); diff --git a/tests/1-ds/test_merge_sort_tree.cpp b/tests/1-ds/test_merge_sort_tree.cpp index 5d8ef3b..4f0eada 100644 --- a/tests/1-ds/test_merge_sort_tree.cpp +++ b/tests/1-ds/test_merge_sort_tree.cpp @@ -11,14 +11,14 @@ ll rnd(ll l, ll r) { return dis(rng); } -int count_greater(const vector &a, int l, int r, int k) { +int count_greater(const vi &a, int l, int r, int k) { int ret = 0; for (int i = l; i <= r; i++) ret += (a[i] > k); return ret; } void test_merge_sort_tree_basic() { - vector a = {5}; + vi a = {5}; merge_seg st; st.build(a); assert(st.query(0, 0, 4) == 1); @@ -27,7 +27,7 @@ void test_merge_sort_tree_basic() { void test_merge_sort_tree_random() { int n = 60; - vector a(n); + vi a(n); for (int i = 0; i < n; i++) a[i] = (int)rnd(-10, 10); merge_seg st; @@ -42,7 +42,7 @@ void test_merge_sort_tree_random() { } void test_merge_sort_tree_iter_basic() { - vector a = {2}; + vi a = {2}; merge_seg_it st; st.build(a); assert(st.query(0, 0, 1) == 1); @@ -51,7 +51,7 @@ void test_merge_sort_tree_iter_basic() { void test_merge_sort_tree_iter_random() { int n = 60; - vector a(n); + vi a(n); for (int i = 0; i < n; i++) a[i] = (int)rnd(-10, 10); merge_seg_it st; diff --git a/tests/1-ds/test_segment_tree.cpp b/tests/1-ds/test_segment_tree.cpp index b564e35..a7a7744 100644 --- a/tests/1-ds/test_segment_tree.cpp +++ b/tests/1-ds/test_segment_tree.cpp @@ -11,13 +11,13 @@ ll rnd(ll l, ll r) { return dis(rng); } -ll sum_range(const vector &a, int l, int r) { +ll sum_range(const vl &a, int l, int r) { ll ret = 0; for (int i = l; i <= r; i++) ret += a[i]; return ret; } -int kth_naive_freq(const vector &a, ll k) { +int kth_naive_freq(const vl &a, ll k) { ll cur = 0; for (int i = 1; i < sz(a); i++) { cur += a[i]; @@ -27,7 +27,7 @@ int kth_naive_freq(const vector &a, ll k) { } void test_segt_basic() { - vector a = {0, 3}; + vl a = {0, 3}; seg_tree st; st.build(a); assert(st.query(1, 1) == 3); @@ -37,7 +37,7 @@ void test_segt_basic() { void test_segt_random() { int n = 50; - vector a(n + 1, 0); + vl a(n + 1, 0); for (int i = 1; i <= n; i++) a[i] = rnd(-5, 5); seg_tree st; @@ -59,7 +59,7 @@ void test_segt_random() { } void test_segti_basic() { - vector a = {4}; + vl a = {4}; seg_tree_it st; st.build(a); assert(st.query(0, 1) == 4); @@ -69,7 +69,7 @@ void test_segti_basic() { void test_segti_random() { int n = 50; - vector a(n, 0); + vl a(n, 0); for (int i = 0; i < n; i++) a[i] = rnd(-5, 5); seg_tree_it st; @@ -105,7 +105,7 @@ void test_segk_basic() { void test_segk_random() { int n = 40; - vector a(n + 1, 0); + vl a(n + 1, 0); seg_tree_kth st; st.init(n); @@ -127,7 +127,7 @@ void test_segk_random() { } void test_seglz_basic() { - vector a = {0, 1, 2}; + vl a = {0, 1, 2}; seg_tree_lz st; st.build(a); st.add(1, 2, 3); @@ -136,7 +136,7 @@ void test_seglz_basic() { void test_seglz_random() { int n = 40; - vector a(n + 1, 0); + vl a(n + 1, 0); for (int i = 1; i <= n; i++) a[i] = rnd(-5, 5); seg_tree_lz st; @@ -160,7 +160,7 @@ void test_seglz_random() { void test_pst_basic() { int n = 3; - vector a = {0, 1, 2, 3}; + vl a = {0, 1, 2, 3}; seg_pst st; st.build(n, a); st.set(2, 5); @@ -170,8 +170,8 @@ void test_pst_basic() { void test_pst_random() { int n = 20; - vector> ver; - vector a(n + 1, 0); + vvl ver; + vl a(n + 1, 0); for (int i = 1; i <= n; i++) a[i] = rnd(-5, 5); ver.pb(a); @@ -183,7 +183,7 @@ void test_pst_random() { if (op == 0) { int p = (int)rnd(1, n); ll v = rnd(-5, 5); - vector nw = ver.back(); + vl nw = ver.back(); nw[p] = v; ver.pb(nw); st.set(p, v); @@ -198,7 +198,7 @@ void test_pst_random() { void test_pst_kth_basic() { int n = 5; - vector a = {0, 2, 0, 1, 3, 0}; + vl a = {0, 2, 0, 1, 3, 0}; seg_pst st; st.build(n, a); assert(st.kth(1, 0) == 1); @@ -214,8 +214,8 @@ void test_pst_kth_basic() { void test_pst_kth_random() { int n = 40; - vector> ver; - vector a(n + 1, 0); + vvl ver; + vl a(n + 1, 0); for (int i = 1; i <= n; i++) a[i] = rnd(0, 3); ver.pb(a); @@ -227,7 +227,7 @@ void test_pst_kth_random() { if (op == 0) { int p = (int)rnd(1, n); ll v = rnd(0, 5); - vector nw = ver.back(); + vl nw = ver.back(); nw[p] = v; ver.pb(nw); st.set(p, v); @@ -276,7 +276,7 @@ void test_dyseg_random() { } } -ll sum_rect(const vector> &a, int x1, int y1, int x2, int y2) { +ll sum_rect(const vvl &a, int x1, int y1, int x2, int y2) { ll ret = 0; for (int i = x1; i <= x2; i++) for (int j = y1; j <= y2; j++) ret += a[i][j]; @@ -284,7 +284,7 @@ ll sum_rect(const vector> &a, int x1, int y1, int x2, int y2) { } void test_seg2d_basic() { - vector> a = {{7}}; + vvl a = {{7}}; seg_2d st; st.build(a); assert(st.query(0, 0, 0, 0) == 7); @@ -294,7 +294,7 @@ void test_seg2d_basic() { void test_seg2d_random() { int n = 7; - vector> a(n, vector(n, 0)); + vvl a(n, vl(n, 0)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) a[i][j] = rnd(-3, 3); @@ -340,7 +340,7 @@ void test_seg2dc_basic() { } st.prep(); - vector> a(n, vector(n, 0)); + vvl a(n, vl(n, 0)); for (auto &op : ops) { if (op.type == 0) { a[op.x1][op.y1] = op.val; @@ -386,7 +386,7 @@ void test_seg2dc_random() { } st.prep(); - vector> a(n, vector(n, 0)); + vvl a(n, vl(n, 0)); for (auto &op : ops) { if (op.type == 0) { a[op.x1][op.y1] = op.val; diff --git a/tests/1-ds/test_union_find.cpp b/tests/1-ds/test_union_find.cpp index d699179..c890040 100644 --- a/tests/1-ds/test_union_find.cpp +++ b/tests/1-ds/test_union_find.cpp @@ -12,8 +12,8 @@ ll rnd(ll l, ll r) { } struct naive_dsu { - vector comp; - vector siz; + vi comp; + vi siz; void init(int n) { comp.resize(n); diff --git a/tests/2-graph/test_bcc.cpp b/tests/2-graph/test_bcc.cpp index 35b34df..3ead5a1 100644 --- a/tests/2-graph/test_bcc.cpp +++ b/tests/2-graph/test_bcc.cpp @@ -12,7 +12,7 @@ int rnd(int l, int r) { } int ccnt(int n, const vector &ed, int sv, int se) { - vector> adj(n + 1); + vvi adj(n + 1); for (int i = 0; i < sz(ed); i++) { if (i == se) continue; int u = ed[i].fr, v = ed[i].sc; @@ -20,7 +20,7 @@ int ccnt(int n, const vector &ed, int sv, int se) { adj[u].pb(v); adj[v].pb(u); } - vector vis(n + 1); + vi vis(n + 1); int cnt = 0; for (int v = 1; v <= n; v++) { if (v == sv || vis[v]) continue; @@ -39,9 +39,9 @@ int ccnt(int n, const vector &ed, int sv, int se) { return cnt; } -vector ap_na(int n, const vector &ed) { +vi ap_na(int n, const vector &ed) { int base = ccnt(n, ed, 0, -1); - vector ap; + vi ap; for (int v = 1; v <= n; v++) if (ccnt(n, ed, v, -1) > base) ap.pb(v); return ap; @@ -86,7 +86,7 @@ void chk_bcc(int n, const vector &ed, bcc_graph &g) { } for (int i = 0; i < sz(comp); i++) { int u = comp[i].fr, v = comp[i].sc; - vector vis(n + 1); + vi vis(n + 1); queue q; q.push(u); vis[u] = 1; @@ -115,7 +115,7 @@ void t_fix() { auto ae = g.ae; sort(all(ap)); sort(all(ae)); - assert(ap == vector({2})); + assert(ap == vi({2})); assert(ae == vector({{1, 2}, {2, 3}})); chk_bcc(n, ed, g); } diff --git a/tests/2-graph/test_euler_circuit.cpp b/tests/2-graph/test_euler_circuit.cpp index 7f4795b..f245078 100644 --- a/tests/2-graph/test_euler_circuit.cpp +++ b/tests/2-graph/test_euler_circuit.cpp @@ -11,7 +11,7 @@ int rnd(int l, int r) { return dis(rng); } -int ecnt(int n, const vector> &cnt) { +int ecnt(int n, const vvi &cnt) { int m = 0; for (int i = 1; i <= n; i++) m += cnt[i][i]; for (int i = 1; i <= n; i++) @@ -19,8 +19,8 @@ int ecnt(int n, const vector> &cnt) { return m; } -bool can_na(int n, const vector> &cnt) { - vector deg(n + 1); +bool can_na(int n, const vvi &cnt) { + vi deg(n + 1); for (int i = 1; i <= n; i++) { deg[i] += 2 * cnt[i][i]; for (int j = 1; j <= n; j++) @@ -35,7 +35,7 @@ bool can_na(int n, const vector> &cnt) { break; } if (!s) return 1; - vector vis(n + 1); + vi vis(n + 1); queue q; q.push(s); vis[s] = 1; @@ -53,13 +53,13 @@ bool can_na(int n, const vector> &cnt) { return 1; } -void add_ed(euler_cir &g, vector> &cnt, int u, int v) { +void add_ed(euler_cir &g, vvi &cnt, int u, int v) { g.add(u, v); if (u == v) cnt[u][u]++; else cnt[u][v]++, cnt[v][u]++; } -void chk_run(int n, const vector> &cnt, const vector &path) { +void chk_run(int n, const vvi &cnt, const vi &path) { int m = ecnt(n, cnt); if (m == 0) { assert(sz(path) == 1); @@ -86,7 +86,7 @@ void t_fix() { int n = 3; euler_cir g; g.init(n); - vector> cnt(n + 1, vector(n + 1)); + vvi cnt(n + 1, vi(n + 1)); add_ed(g, cnt, 1, 2); add_ed(g, cnt, 2, 3); add_ed(g, cnt, 3, 1); @@ -95,7 +95,7 @@ void t_fix() { chk_run(n, cnt, path); g.init(n); - cnt.assign(n + 1, vector(n + 1)); + cnt.assign(n + 1, vi(n + 1)); add_ed(g, cnt, 1, 2); add_ed(g, cnt, 2, 3); assert(!g.can()); @@ -107,7 +107,7 @@ void t_rnd() { int m = rnd(0, 8); euler_cir g; g.init(n); - vector> cnt(n + 1, vector(n + 1)); + vvi cnt(n + 1, vi(n + 1)); for (int i = 0; i < m; i++) { int u = rnd(1, n), v = rnd(1, n); add_ed(g, cnt, u, v); @@ -117,7 +117,7 @@ void t_rnd() { assert(ok1 == ok2); if (ok1) { int s = 1; - vector deg(n + 1); + vi deg(n + 1); for (int i = 1; i <= n; i++) { deg[i] += 2 * cnt[i][i]; for (int j = 1; j <= n; j++) diff --git a/tests/2-graph/test_kth_shortest_path.cpp b/tests/2-graph/test_kth_shortest_path.cpp index e8c5f25..e673886 100644 --- a/tests/2-graph/test_kth_shortest_path.cpp +++ b/tests/2-graph/test_kth_shortest_path.cpp @@ -13,11 +13,11 @@ int rnd(int l, int r) { kth_walk ks; -vector kth_na(int n, const vector> &g, int s, int e, int k) { - vector cnt(n + 1); +vl kth_na(int n, const vector> &g, int s, int e, int k) { + vi cnt(n + 1); priority_queue, greater> pq; pq.push({0, s}); - vector res; + vl res; while (!pq.empty() && sz(res) < k) { auto [d, v] = pq.top(); pq.pop(); diff --git a/tests/2-graph/test_offline_dynamic_connectivity.cpp b/tests/2-graph/test_offline_dynamic_connectivity.cpp index e446d07..a11f68f 100644 --- a/tests/2-graph/test_offline_dynamic_connectivity.cpp +++ b/tests/2-graph/test_offline_dynamic_connectivity.cpp @@ -13,12 +13,12 @@ int rnd(int l, int r) { int conn(int n, const set &act, int s, int e) { if (s == e) return 1; - vector> adj(n + 1); + vvi adj(n + 1); for (auto [u, v] : act) { adj[u].pb(v); adj[v].pb(u); } - vector vis(n + 1); + vi vis(n + 1); queue q; q.push(s); vis[s] = 1; @@ -34,7 +34,7 @@ int conn(int n, const set &act, int s, int e) { void t_fix() { int n = 4, q = 6; - vector op(q + 1), u(q + 1), v(q + 1), ans(q + 1); + vi op(q + 1), u(q + 1), v(q + 1), ans(q + 1); op[1] = 1, u[1] = 1, v[1] = 2; op[2] = 3, u[2] = 1, v[2] = 3; op[3] = 1, u[3] = 2, v[3] = 3; @@ -64,7 +64,7 @@ void t_rnd() { for (int it = 0; it < 200; it++) { int n = rnd(2, 8); int q = rnd(1, 40); - vector op(q + 1), u(q + 1), v(q + 1), ans(q + 1); + vi op(q + 1), u(q + 1), v(q + 1), ans(q + 1); set act; for (int i = 1; i <= q; i++) { int t = rnd(0, 9); diff --git a/tests/2-graph/test_scc_2_sat.cpp b/tests/2-graph/test_scc_2_sat.cpp index 9565f46..97e303b 100644 --- a/tests/2-graph/test_scc_2_sat.cpp +++ b/tests/2-graph/test_scc_2_sat.cpp @@ -11,8 +11,8 @@ int rnd(int l, int r) { return dis(rng); } -vector> rch(int n, const vector> &g) { - vector> r(n + 1, vector(n + 1)); +vvi rch(int n, const vvi &g) { + vvi r(n + 1, vi(n + 1)); for (int s = 1; s <= n; s++) { queue q; q.push(s); @@ -28,9 +28,9 @@ vector> rch(int n, const vector> &g) { return r; } -vector cmp_na(int n, const vector> &g) { +vi cmp_na(int n, const vvi &g) { auto r = rch(n, g); - vector cmp(n + 1, -1); + vi cmp(n + 1, -1); int cid = 0; for (int i = 1; i <= n; i++) { if (cmp[i] != -1) continue; @@ -41,7 +41,7 @@ vector cmp_na(int n, const vector> &g) { return cmp; } -bool sat_br(int n, const vector &cl, vector &val) { +bool sat_br(int n, const vector &cl, vi &val) { int lim = 1 << n; for (int mask = 0; mask < lim; mask++) { bool ok = 1; @@ -65,7 +65,7 @@ void t_scc() { for (int it = 0; it < 200; it++) { int n = rnd(1, 7); int m = rnd(0, n * (n - 1)); - vector> g(n + 1); + vvi g(n + 1); for (int i = 0; i < m; i++) { int u = rnd(1, n), v = rnd(1, n); g[u].pb(v); @@ -106,7 +106,7 @@ void t_sat() { if (rnd(0, 1)) b = -b; cl.pb({a, b}); } - vector val; + vi val; bool ok2 = sat_br(n, cl, val); two_sat ts; diff --git a/tests/2-graph/test_shortest_path.cpp b/tests/2-graph/test_shortest_path.cpp index 63dcc1a..42e120d 100644 --- a/tests/2-graph/test_shortest_path.cpp +++ b/tests/2-graph/test_shortest_path.cpp @@ -11,9 +11,9 @@ int rnd(int l, int r) { return dis(rng); } -vector> floy(int n, const vector> &ed) { +vvl floy(int n, const vector> &ed) { const ll INF = (1LL << 60); - vector> d(n + 1, vector(n + 1, INF)); + vvl d(n + 1, vl(n + 1, INF)); for (int i = 1; i <= n; i++) d[i][i] = 0; for (auto [u, v, w] : ed) d[u][v] = min(d[u][v], w); for (int k = 1; k <= n; k++) @@ -70,7 +70,7 @@ void t_bell() { bool neg = 0; for (int v = 1; v <= n; v++) if (d[s][v] < INF / 2 && d[v][v] < 0) neg = 1; - vector dist; + vl dist; bool ok = bl.run(s, dist); if (neg) { assert(!ok); diff --git a/tests/3-tree/test_centroid_decomp.cpp b/tests/3-tree/test_centroid_decomp.cpp index 3404b05..8501a07 100644 --- a/tests/3-tree/test_centroid_decomp.cpp +++ b/tests/3-tree/test_centroid_decomp.cpp @@ -11,18 +11,18 @@ int rnd(int l, int r) { return dis(rng); } -void add_edge(vector> &adj, int u, int v) { +void add_edge(vvi &adj, int u, int v) { adj[u].pb(v); adj[v].pb(u); } -vector> gen_tree(int n) { - vector> adj(n + 1); +vvi gen_tree(int n) { + vvi adj(n + 1); for (int v = 2; v <= n; v++) add_edge(adj, v, rnd(1, v - 1)); return adj; } -int get_root(int n, const vector &par) { +int get_root(int n, const vi &par) { int root = 0; for (int v = 1; v <= n; v++) if (!par[v]) { @@ -33,7 +33,7 @@ int get_root(int n, const vector &par) { return root; } -void get_sub(int v, const vector> &chd, vector &sub) { +void get_sub(int v, const vvi &chd, vi &sub) { sub[v] = 1; for (int to : chd[v]) { get_sub(to, chd, sub); @@ -41,9 +41,9 @@ void get_sub(int v, const vector> &chd, vector &sub) { } } -vector get_nodes(int v, const vector> &chd) { - vector res; - vector st = {v}; +vi get_nodes(int v, const vvi &chd) { + vi res; + vi st = {v}; while (!st.empty()) { int x = st.back(); st.pop_back(); @@ -53,7 +53,7 @@ vector get_nodes(int v, const vector> &chd) { return res; } -void check_one(const vector> &adj) { +void check_one(const vvi &adj) { int n = sz(adj) - 1; cen_decomp cd; cd.init(n); @@ -65,7 +65,7 @@ void check_one(const vector> &adj) { int root = get_root(n, cd.par); // check: centroid tree is a rooted tree on [1..n]. - vector vis(n + 1); + vi vis(n + 1); queue q; q.push(root); vis[root] = 1; @@ -85,7 +85,7 @@ void check_one(const vector> &adj) { assert(cnt == n); assert(edges == n - 1); - vector sub(n + 1); + vi sub(n + 1); get_sub(root, cd.chd, sub); // check: centroid property (each child component size <= half). @@ -98,7 +98,7 @@ void check_one(const vector> &adj) { vector in_c(n + 1, 0); for (int v : nodes_c) in_c[v] = 1; - vector first(n + 1, 0); + vi first(n + 1, 0); queue qq; for (int nb : adj[c]) { if (!in_c[nb]) continue; @@ -117,7 +117,7 @@ void check_one(const vector> &adj) { for (int v : nodes_c) if (v != c) assert(first[v]); - vector labs; + vi labs; for (int x : cd.chd[c]) { int lab = first[x]; assert(lab); @@ -134,24 +134,24 @@ void check_one(const vector> &adj) { void t_fix() { { int n = 1; - vector> adj(n + 1); + vvi adj(n + 1); check_one(adj); } { int n = 2; - vector> adj(n + 1); + vvi adj(n + 1); add_edge(adj, 1, 2); check_one(adj); } { int n = 7; - vector> adj(n + 1); + vvi adj(n + 1); for (int i = 1; i < n; i++) add_edge(adj, i, i + 1); check_one(adj); } { int n = 9; - vector> adj(n + 1); + vvi adj(n + 1); for (int i = 2; i <= n; i++) add_edge(adj, 1, i); check_one(adj); } diff --git a/tests/3-tree/test_hld.cpp b/tests/3-tree/test_hld.cpp index e498e74..017ace1 100644 --- a/tests/3-tree/test_hld.cpp +++ b/tests/3-tree/test_hld.cpp @@ -11,8 +11,8 @@ int rnd(int l, int r) { return dis(rng); } -vector path_nodes(int n, const vector> &adj, int s, int e) { - vector par(n + 1, -1); +vi path_nodes(int n, const vvi &adj, int s, int e) { + vi par(n + 1, -1); queue q; q.push(s); par[s] = s; @@ -26,7 +26,7 @@ vector path_nodes(int n, const vector> &adj, int s, int e) { q.push(to); } } - vector res; + vi res; int v = e; while (v != par[v]) { res.pb(v); @@ -38,7 +38,7 @@ vector path_nodes(int n, const vector> &adj, int s, int e) { void t_fix() { int n = 4; - vector> adj(n + 1); + vvi adj(n + 1); auto add = [&](int u, int v) { adj[u].pb(v); adj[v].pb(u); @@ -53,7 +53,7 @@ void t_fix() { for (int v : adj[u]) if (u < v) h.add(u, v); h.build(1); - vector val = {0, 1, 2, 3, 4}; + vl val = {0, 1, 2, 3, 4}; for (int i = 1; i <= n; i++) h.set(i, val[i]); auto p = path_nodes(n, adj, 3, 4); ll sum = 0; @@ -64,8 +64,8 @@ void t_fix() { void t_rnd() { for (int it = 0; it < 200; it++) { int n = rnd(2, 9); - vector par(n + 1, 0); - vector> adj(n + 1); + vi par(n + 1, 0); + vvi adj(n + 1); for (int v = 2; v <= n; v++) { par[v] = rnd(1, v - 1); adj[v].pb(par[v]); @@ -75,7 +75,7 @@ void t_rnd() { h.init(n); for (int v = 2; v <= n; v++) h.add(v, par[v]); h.build(1); - vector val(n + 1); + vl val(n + 1); for (int i = 1; i <= n; i++) { val[i] = rnd(-5, 5); h.set(i, val[i]); diff --git a/tests/3-tree/test_lca_sparse_table.cpp b/tests/3-tree/test_lca_sparse_table.cpp index 251db0f..f6e1e66 100644 --- a/tests/3-tree/test_lca_sparse_table.cpp +++ b/tests/3-tree/test_lca_sparse_table.cpp @@ -11,8 +11,8 @@ int rnd(int l, int r) { return dis(rng); } -int lca_na(int n, const vector> &adj, int root, int a, int b) { - vector par(n + 1, 0), dep(n + 1, 0); +int lca_na(int n, const vvi &adj, int root, int a, int b) { + vi par(n + 1, 0), dep(n + 1, 0); queue q; q.push(root); par[root] = root; @@ -35,8 +35,8 @@ int lca_na(int n, const vector> &adj, int root, int a, int b) { void t_rnd() { for (int it = 0; it < 200; it++) { int n = rnd(2, 20); - vector par(n + 1, 0); - vector> adj(n + 1); + vi par(n + 1, 0); + vvi adj(n + 1); for (int v = 2; v <= n; v++) { par[v] = rnd(1, v - 1); adj[v].pb(par[v]); diff --git a/tests/3-tree/test_tree_composition.cpp b/tests/3-tree/test_tree_composition.cpp index 389bd2f..fd806ca 100644 --- a/tests/3-tree/test_tree_composition.cpp +++ b/tests/3-tree/test_tree_composition.cpp @@ -11,18 +11,18 @@ int rnd(int l, int r) { return dis(rng); } -void add_edge(vector> &adj, int u, int v) { +void add_edge(vvi &adj, int u, int v) { adj[u].pb(v); adj[v].pb(u); } -vector> gen_tree(int n) { - vector> adj(n + 1); +vvi gen_tree(int n) { + vvi adj(n + 1); for (int v = 2; v <= n; v++) add_edge(adj, v, rnd(1, v - 1)); return adj; } -void root_tree(int n, const vector> &adj, int root, vector &par, vector &dep) { +void root_tree(int n, const vvi &adj, int root, vi &par, vi &dep) { par.assign(n + 1, -1); dep.assign(n + 1, 0); queue q; @@ -42,14 +42,14 @@ void root_tree(int n, const vector> &adj, int root, vector &par for (int v = 1; v <= n; v++) assert(par[v] != -1); } -int lca_na(int a, int b, const vector &par, const vector &dep) { +int lca_na(int a, int b, const vi &par, const vi &dep) { while (dep[a] > dep[b]) a = par[a]; while (dep[b] > dep[a]) b = par[b]; while (a != b) a = par[a], b = par[b]; return a; } -vector lca_closure(vector vs, const vector &par, const vector &dep) { +vi lca_closure(vi vs, const vi &par, const vi &dep) { int n = sz(par) - 1; sort(all(vs)); vs.erase(unique(all(vs)), vs.end()); @@ -76,9 +76,9 @@ vector lca_closure(vector vs, const vector &par, const vector> &adj, const vector &vs) { +void check_one(const vvi &adj, const vi &vs) { int n = sz(adj) - 1; - vector par, dep; + vi par, dep; root_tree(n, adj, 1, par, dep); tree_comp tc; @@ -102,7 +102,7 @@ void check_one(const vector> &adj, const vector &vs) { vector in_set(n + 1, 0); for (int v : exp_nodes) in_set[v] = 1; - vector in_cnt(n + 1, 0), par_vt(n + 1, 0); + vi in_cnt(n + 1, 0), par_vt(n + 1, 0); int edges = 0; for (int v : exp_nodes) for (int to : tc.vt_adj[v]) { @@ -132,8 +132,8 @@ void check_one(const vector> &adj, const vector &vs) { } } - vector vis(n + 1); - vector st = {root}; + vi vis(n + 1); + vi st = {root}; vis[root] = 1; while (!st.empty()) { int v = st.back(); @@ -149,13 +149,13 @@ void check_one(const vector> &adj, const vector &vs) { void t_fix() { { int n = 1; - vector> adj(n + 1); + vvi adj(n + 1); check_one(adj, {}); check_one(adj, {1}); } { int n = 5; - vector> adj(n + 1); + vvi adj(n + 1); for (int i = 1; i < n; i++) add_edge(adj, i, i + 1); check_one(adj, {3}); check_one(adj, {2, 4}); @@ -169,7 +169,7 @@ void t_rnd() { int n = rnd(2, 30); auto adj = gen_tree(n); int k = rnd(0, n); - vector vs; + vi vs; for (int i = 0; i < k; i++) vs.pb(rnd(1, n)); check_one(adj, vs); } diff --git a/tests/3-tree/test_tree_exchange_argument.cpp b/tests/3-tree/test_tree_exchange_argument.cpp index 798e991..14f0023 100644 --- a/tests/3-tree/test_tree_exchange_argument.cpp +++ b/tests/3-tree/test_tree_exchange_argument.cpp @@ -11,20 +11,20 @@ int rnd(int l, int r) { return dis(rng); } -void add_edge(vector> &adj, int u, int v) { +void add_edge(vvi &adj, int u, int v) { adj[u].pb(v); adj[v].pb(u); } -vector> gen_tree(int n) { - vector> adj(n + 1); +vvi gen_tree(int n) { + vvi adj(n + 1); for (int v = 2; v <= n; v++) add_edge(adj, v, rnd(1, v - 1)); return adj; } -vector> get_child(int n, const vector> &adj, int root) { - vector> ch(n + 1); - vector par(n + 1, -1); +vvi get_child(int n, const vvi &adj, int root) { + vvi ch(n + 1); + vi par(n + 1, -1); queue q; q.push(root); par[root] = 0; @@ -43,19 +43,19 @@ vector> get_child(int n, const vector> &adj, int root) { return ch; } -ll brute_max(int n, const vector> &ch, const vector &w, const vector &t) { - vector indeg(n + 1, 0); +ll brute_max(int n, const vvi &ch, const vl &w, const vl &t) { + vi indeg(n + 1, 0); for (int v = 1; v <= n; v++) for (int to : ch[v]) indeg[to]++; - vector avail; + vi avail; for (int v = 1; v <= n; v++) if (!indeg[v]) avail.pb(v); ll best = -(1LL << 62); - vector ord; + vi ord; ord.reserve(n); - function &, vector &, ll, ll)> dfs = [&](vector &id, vector &av, - ll tm, ll cost) { + function dfs = [&](vi &id, vi &av, + ll tm, ll cost) { if (sz(ord) == n) { best = max(best, cost); return; @@ -63,8 +63,8 @@ ll brute_max(int n, const vector> &ch, const vector &w, const ve for (int i = 0; i < sz(av); i++) { int v = av[i]; ord.pb(v); - vector id2 = id; - vector av2 = av; + vi id2 = id; + vi av2 = av; av2.erase(av2.begin() + i); ll tm2 = tm + t[v]; ll cost2 = cost + w[v] * tm2; @@ -80,7 +80,7 @@ ll brute_max(int n, const vector> &ch, const vector &w, const ve return best; } -void check_one(const vector> &adj, int root, const vector &w, const vector &t) { +void check_one(const vvi &adj, int root, const vl &w, const vl &t) { int n = sz(adj) - 1; auto ch = get_child(n, adj, root); ll exp = brute_max(n, ch, w, t); @@ -102,11 +102,11 @@ void check_one(const vector> &adj, int root, const vector &w, co void t_fix() { { int n = 3; - vector> adj(n + 1); + vvi adj(n + 1); add_edge(adj, 1, 2); add_edge(adj, 1, 3); - vector w = {0, 1, 2, 3}; - vector t = {0, 1, 1, 1}; + vl w = {0, 1, 2, 3}; + vl t = {0, 1, 1, 1}; check_one(adj, 1, w, t); } } @@ -116,7 +116,7 @@ void t_rnd() { int n = rnd(1, 9); auto adj = gen_tree(n); int root = rnd(1, n); - vector w(n + 1), t(n + 1); + vl w(n + 1), t(n + 1); for (int i = 1; i <= n; i++) { w[i] = rnd(0, 7); t[i] = rnd(1, 4); diff --git a/tests/4-optimizations/test_flow.cpp b/tests/4-optimizations/test_flow.cpp index 89c8bbe..4598806 100644 --- a/tests/4-optimizations/test_flow.cpp +++ b/tests/4-optimizations/test_flow.cpp @@ -32,7 +32,7 @@ struct ek_flow { if (s == t) return 0; ll flow = 0; while (1) { - vector pv(n, -1), pe(n, -1); + vi pv(n, -1), pe(n, -1); queue q; q.push(s); pv[s] = s; @@ -62,8 +62,8 @@ struct ek_flow { } }; -int brute_match(int n_l, int n_r, const vector> &g) { - vector> dp(n_l + 1, vector(1 << n_r, -1)); +int brute_match(int n_l, int n_r, const vvi &g) { + vvi dp(n_l + 1, vi(1 << n_r, -1)); function go = [&](int i, int mask) { if (i == n_l) return 0; int &ret = dp[i][mask]; @@ -97,8 +97,8 @@ struct mcmf_spfa { const ll INF = (1LL << 62); ll flow = 0, cost = 0; while (flow < max_f) { - vector dist(n, INF); - vector pv(n, -1), pe(n, -1); + vl dist(n, INF); + vi pv(n, -1), pe(n, -1); queue q; vector in_q(n, 0); dist[s] = 0; @@ -145,11 +145,11 @@ struct lr_res { lr_res brute_lr(int n, int s, int t, const vector> &es) { int m = sz(es); - vector f(m, 0); + vi f(m, 0); ll best_f = -(1LL << 62), best_c = (1LL << 62); function dfs = [&](int i) { if (i == m) { - vector bal(n, 0); + vi bal(n, 0); ll cost = 0; for (int k = 0; k < m; k++) { auto [u, v, lo, hi, c] = es[k]; @@ -207,7 +207,7 @@ void t_hk() { for (int it = 0; it < 300; it++) { int n_l = rnd(0, 10), n_r = rnd(0, 10); hk bm(n_l, n_r); - vector> g(n_l); + vvi g(n_l); for (int l = 0; l < n_l; l++) for (int r = 0; r < n_r; r++) if (rnd(0, 1)) bm.add_edge(l, r), g[l].pb(r); diff --git a/tests/4-optimizations/test_hungarian.cpp b/tests/4-optimizations/test_hungarian.cpp index bbd518e..4f880f4 100644 --- a/tests/4-optimizations/test_hungarian.cpp +++ b/tests/4-optimizations/test_hungarian.cpp @@ -11,10 +11,10 @@ int rnd(int l, int r) { return dis(rng); } -pair> brute(int n, int m, const vector> &a) { +pair brute(int n, int m, const vvl &a) { ll best = (1LL << 62); - vector best_m(n + 1, 0); - vector cur(n + 1, 0); + vi best_m(n + 1, 0); + vi cur(n + 1, 0); vector used(m + 1, 0); function dfs = [&](int i, ll cost) { if (i == n + 1) { @@ -35,7 +35,7 @@ pair> brute(int n, int m, const vector> &a) { void t_fix() { int n = 1, m = 1; - vector> a(n + 1, vector(m + 1, 0)); + vvl a(n + 1, vl(m + 1, 0)); a[1][1] = 7; hungarian hu; auto [cost, match_l] = hu.run(n, m, a); @@ -47,7 +47,7 @@ void t_rnd() { for (int it = 0; it < 200; it++) { int n = rnd(1, 6); int m = rnd(n, 7); - vector> a(n + 1, vector(m + 1, 0)); + vvl a(n + 1, vl(m + 1, 0)); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) a[i][j] = rnd(-5, 7); hungarian hu; diff --git a/tests/5-string/test_kmp_algorithm.cpp b/tests/5-string/test_kmp_algorithm.cpp index dd98755..2869571 100644 --- a/tests/5-string/test_kmp_algorithm.cpp +++ b/tests/5-string/test_kmp_algorithm.cpp @@ -16,8 +16,8 @@ string rnd_s(int n) { return s; } -vector na_match(const string &t, const string &p) { - vector res; +vi na_match(const string &t, const string &p) { + vi res; if (p.empty()) return res; for (int i = 0; i + sz(p) <= sz(t); i++) if (!t.compare(i, sz(p), p)) res.pb(i); @@ -25,8 +25,8 @@ vector na_match(const string &t, const string &p) { } void t_fix() { - assert((kmp_match("ababa", "aba") == vector{0, 2})); - assert((kmp_match("aaaaa", "aa") == vector{0, 1, 2, 3})); + assert((kmp_match("ababa", "aba") == vi{0, 2})); + assert((kmp_match("aaaaa", "aa") == vi{0, 1, 2, 3})); } void t_rnd() { diff --git a/tests/5-string/test_rabin_karp_algorithm.cpp b/tests/5-string/test_rabin_karp_algorithm.cpp index 24b9ffb..9ff82db 100644 --- a/tests/5-string/test_rabin_karp_algorithm.cpp +++ b/tests/5-string/test_rabin_karp_algorithm.cpp @@ -16,8 +16,8 @@ string rnd_s(int n) { return s; } -vector na_match(const string &t, const string &p) { - vector res; +vi na_match(const string &t, const string &p) { + vi res; if (p.empty()) return res; for (int i = 0; i + sz(p) <= sz(t); i++) if (!t.compare(i, sz(p), p)) res.pb(i); diff --git a/tests/5-string/test_suffix_array.cpp b/tests/5-string/test_suffix_array.cpp index 2f016bd..bd214dd 100644 --- a/tests/5-string/test_suffix_array.cpp +++ b/tests/5-string/test_suffix_array.cpp @@ -39,11 +39,11 @@ void check_one(const string &s) { assert(sa.lcp.empty()); return; } - vector exp(n); + vi exp(n); iota(all(exp), 0); sort(all(exp), [&](int i, int j) { return suf_lt(s, i, j); }); assert(sa.sa == exp); - vector exp_lcp(n, 0); + vi exp_lcp(n, 0); for (int i = 1; i < n; i++) exp_lcp[i] = lcp2(s, exp[i], exp[i - 1]); assert(sa.lcp == exp_lcp); } diff --git a/tests/5-string/test_z_algorithm.cpp b/tests/5-string/test_z_algorithm.cpp index a24cf95..ca04a38 100644 --- a/tests/5-string/test_z_algorithm.cpp +++ b/tests/5-string/test_z_algorithm.cpp @@ -16,9 +16,9 @@ string rnd_s(int n) { return s; } -vector na_z(const string &s) { +vi na_z(const string &s) { int n = sz(s); - vector z(n); + vi z(n); for (int i = 0; i < n; i++) { int k = 0; while (i + k < n && s[k] == s[i + k]) k++; diff --git a/tests/6-geometry/test_bulldozer_trick.cpp b/tests/6-geometry/test_bulldozer_trick.cpp index 4e4f499..ddc07b5 100644 --- a/tests/6-geometry/test_bulldozer_trick.cpp +++ b/tests/6-geometry/test_bulldozer_trick.cpp @@ -20,14 +20,14 @@ vector uniq_ang(vector v) { return u; } -vector perm(const vector &p, map &id) { - vector res; +vi perm(const vector &p, map &id) { + vi res; res.reserve(sz(p)); for (auto &v : p) res.pb(id[{v.x, v.y}]); return res; } -vector proj_ord(const vector &p, map &id, ld ang) { +vi proj_ord(const vector &p, map &id, ld ang) { ld cs = cosl(ang), sn = sinl(ang); vector> arr; arr.reserve(sz(p)); @@ -39,7 +39,7 @@ vector proj_ord(const vector &p, map &id, ld ang) { if (fabsl(a.fr - b.fr) > 1e-18) return a.fr < b.fr; return a.sc < b.sc; }); - vector ord; + vi ord; ord.reserve(sz(p)); for (auto &x : arr) ord.pb(x.sc); return ord; @@ -58,7 +58,7 @@ void test_bulldozer_small() { pts.pb(v); } - vector> got; + vvi got; vector cur = pts; bulldozer(cur, [&](const vector &p) { got.pb(perm(p, id)); }); @@ -85,7 +85,7 @@ void test_bulldozer_small() { bnd.pb(PI); bnd = uniq_ang(bnd); - vector> exp; + vvi exp; vector st = pts; sort(all(st)); for (int i = 0; i + 1 < sz(bnd); i++) { diff --git a/tests/7-math/test_comb_cat_der.cpp b/tests/7-math/test_comb_cat_der.cpp index 410dea5..043e9af 100644 --- a/tests/7-math/test_comb_cat_der.cpp +++ b/tests/7-math/test_comb_cat_der.cpp @@ -5,16 +5,16 @@ // constraint: small n. // usage: g++ -std=c++17 test_comb_cat_der.cpp && ./a.out -vector cat_ref(int n) { - vector dp(n + 1, 0); +vl cat_ref(int n) { + vl dp(n + 1, 0); dp[0] = 1; for (int i = 1; i <= n; i++) for (int j = 0; j < i; j++) dp[i] += dp[j] * dp[i - 1 - j]; return dp; } -vector der_ref(int n) { - vector dp(max(3, n + 1), 0); +vl der_ref(int n) { + vl dp(max(3, n + 1), 0); dp[0] = 1; dp[1] = 0; dp[2] = 1; diff --git a/tests/7-math/test_conv_fft.cpp b/tests/7-math/test_conv_fft.cpp index 543bdea..c81b596 100644 --- a/tests/7-math/test_conv_fft.cpp +++ b/tests/7-math/test_conv_fft.cpp @@ -11,18 +11,18 @@ int rnd_int(int l, int r) { return dis(rng); } -vector conv_ref(const vector &a, const vector &b) { +vl conv_ref(const vl &a, const vl &b) { int n = sz(a), m = sz(b); - vector c(n + m - 1, 0); + vl c(n + m - 1, 0); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) c[i + j] += a[i] * b[j]; return c; } -vector conv_mod_ref(const vector &a, const vector &b, ll mod) { +vl conv_mod_ref(const vl &a, const vl &b, ll mod) { int n = sz(a), m = sz(b); - if (mod == 1) return vector(n + m - 1, 0); - vector c(n + m - 1, 0); + if (mod == 1) return vl(n + m - 1, 0); + vl c(n + m - 1, 0); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { ll v = (ll)((__int128)a[i] * b[j] % mod); @@ -38,7 +38,7 @@ void test_fft() { for (int it = 0; it < 200; it++) { int n = rnd_int(1, 20); int m = rnd_int(1, 20); - vector a(n), b(m); + vl a(n), b(m); for (int i = 0; i < n; i++) a[i] = rnd_int(-5, 5); for (int i = 0; i < m; i++) b[i] = rnd_int(-5, 5); auto ref = conv_ref(a, b); @@ -48,7 +48,7 @@ void test_fft() { for (int it = 0; it < 100; it++) { int n = rnd_int(1, 60); int m = rnd_int(1, 60); - vector a(n), b(m); + vl a(n), b(m); for (int i = 0; i < n; i++) a[i] = rnd_int(-100, 100); for (int i = 0; i < m; i++) b[i] = rnd_int(-100, 100); auto ref = conv_ref(a, b); @@ -63,14 +63,14 @@ void test_fft_mod() { for (int it = 0; it < 200; it++) { int n = rnd_int(1, 20); int m = rnd_int(1, 20); - vector a(n), b(m); + vl a(n), b(m); for (int i = 0; i < n; i++) a[i] = rnd_int(0, 1000); for (int i = 0; i < m; i++) b[i] = rnd_int(0, 1000); auto ref = conv_mod_ref(a, b, mod); auto got = fft_conv::mul_mod(a, b, mod); for (int i = 0; i < sz(ref); i++) assert(got[i] == ref[i]); } - auto all0 = fft_conv::mul_mod(vector(5, 0), vector(7, 0), mod); + auto all0 = fft_conv::mul_mod(vl(5, 0), vl(7, 0), mod); for (ll v : all0) assert(v == 0); } @@ -80,7 +80,7 @@ void test_ntt() { for (int it = 0; it < 200; it++) { int n = rnd_int(1, 20); int m = rnd_int(1, 20); - vector a(n), b(m); + vl a(n), b(m); for (int i = 0; i < n; i++) a[i] = rnd_int(0, mod - 1); for (int i = 0; i < m; i++) b[i] = rnd_int(0, mod - 1); auto ref = conv_mod_ref(a, b, mod); @@ -95,7 +95,7 @@ void test_ntt_any() { for (int it = 0; it < 200; it++) { int n = rnd_int(1, 20); int m = rnd_int(1, 20); - vector a(n), b(m); + vl a(n), b(m); for (int i = 0; i < n; i++) a[i] = rnd_int(0, 1000); for (int i = 0; i < m; i++) b[i] = rnd_int(0, 1000); auto ref = conv_mod_ref(a, b, mod); diff --git a/tests/7-math/test_linalg_gauss.cpp b/tests/7-math/test_linalg_gauss.cpp index 1c314e1..25c71a4 100644 --- a/tests/7-math/test_linalg_gauss.cpp +++ b/tests/7-math/test_linalg_gauss.cpp @@ -38,8 +38,8 @@ void test_gauss_real() { void test_gauss_mod() { int n = 6, m = 6; int mod = 101; - vector> A(n, vector(m)); - vector x(m), b(n); + vvi A(n, vi(m)); + vi x(m), b(n); for (int i = 0; i < m; i++) x[i] = rnd_int(0, mod - 1); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) A[i][j] = rnd_int(0, mod - 1); @@ -48,7 +48,7 @@ void test_gauss_mod() { for (int j = 0; j < m; j++) sum += (ll)A[i][j] * x[j]; b[i] = sum % mod; } - vector> aug(n, vector(m + 1)); + vvi aug(n, vi(m + 1)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) aug[i][j] = A[i][j]; aug[i][m] = b[i]; @@ -61,7 +61,7 @@ void test_gauss_mod() { assert(sum % mod == b[i]); } - vector> bad = { + vvi bad = { {1, 0, 0}, {1, 0, 1}, }; @@ -71,7 +71,7 @@ void test_gauss_mod() { void test_gauss_xor() { int n = 40, m = 20; - vector x(m); + vi x(m); for (int i = 0; i < m; i++) x[i] = rnd_int(0, 1); vector> aug(n); for (int i = 0; i < n; i++) { diff --git a/tests/7-math/test_linalg_mat.cpp b/tests/7-math/test_linalg_mat.cpp index 4075ee0..6211ddc 100644 --- a/tests/7-math/test_linalg_mat.cpp +++ b/tests/7-math/test_linalg_mat.cpp @@ -21,9 +21,9 @@ ll fib_ref(int n, ll mod) { return a; } -vector> mul_ref(const vector> &a, const vector> &b, ll mod) { +vvl mul_ref(const vvl &a, const vvl &b, ll mod) { int n = sz(a), m = sz(b[0]), k = sz(a[0]); - vector> r(n, vector(m, 0)); + vvl r(n, vl(m, 0)); for (int i = 0; i < n; i++) for (int t = 0; t < k; t++) for (int j = 0; j < m; j++) { diff --git a/tests/7-math/test_misc_sqrt.cpp b/tests/7-math/test_misc_sqrt.cpp index bd51083..803c1b8 100644 --- a/tests/7-math/test_misc_sqrt.cpp +++ b/tests/7-math/test_misc_sqrt.cpp @@ -18,15 +18,15 @@ bool is_prime_ref(ll x) { return 1; } -vector div_ref(ll x) { - vector d; +vl div_ref(ll x) { + vl d; for (ll i = 1; i <= x; i++) if (x % i == 0) d.pb(i); return d; } -vector fac_ref(ll x) { - vector p; +vl fac_ref(ll x) { + vl p; for (ll i = 2; i <= x / i; i++) { while (x % i == 0) { p.pb(i); @@ -38,10 +38,10 @@ vector fac_ref(ll x) { } int main() { - assert(sqrt_alg::divisors(1) == vector({1})); + assert(sqrt_alg::divisors(1) == vl({1})); assert(sqrt_alg::prime_fac(1).empty()); - assert(sqrt_alg::divisors(36) == vector({1, 2, 3, 4, 6, 9, 12, 18, 36})); - assert(sqrt_alg::prime_fac(36) == vector({2, 2, 3, 3})); + assert(sqrt_alg::divisors(36) == vl({1, 2, 3, 4, 6, 9, 12, 18, 36})); + assert(sqrt_alg::prime_fac(36) == vl({2, 2, 3, 3})); for (int it = 0; it < 1000; it++) { ll x = rnd_ll(1, 5000); auto d1 = sqrt_alg::divisors(x); diff --git a/tests/7-math/test_nt_mr_rho.cpp b/tests/7-math/test_nt_mr_rho.cpp index d4f95f6..ee01015 100644 --- a/tests/7-math/test_nt_mr_rho.cpp +++ b/tests/7-math/test_nt_mr_rho.cpp @@ -18,8 +18,8 @@ bool is_prime_ref(ll x) { return 1; } -vector fac_ref(ll x) { - vector f; +vl fac_ref(ll x) { + vl f; for (ll p = 2; p * p <= x; p++) { while (x % p == 0) { f.pb(p); @@ -56,15 +56,15 @@ void test_factor() { assert(pollard_rho::factor(1).empty()); assert(pollard_rho::factor(0).empty()); auto fneg = pollard_rho::factor(-12); - assert(fneg == vector({2, 2, 3})); + assert(fneg == vl({2, 2, 3})); auto fp = pollard_rho::factor(1000000007LL); - assert(fp == vector({1000000007LL})); + assert(fp == vl({1000000007LL})); ll p = 1000003, q = 1000033; auto fs = pollard_rho::factor(p * q); - assert(fs == vector({p, q})); + assert(fs == vl({p, q})); ll big = 1000000007LL * 1000000009LL; auto fb = pollard_rho::factor(big); - assert(fb == vector({1000000007LL, 1000000009LL})); + assert(fb == vl({1000000007LL, 1000000009LL})); } int main() { diff --git a/tests/7-math/test_nt_sieve.cpp b/tests/7-math/test_nt_sieve.cpp index ba0704c..de243de 100644 --- a/tests/7-math/test_nt_sieve.cpp +++ b/tests/7-math/test_nt_sieve.cpp @@ -45,8 +45,8 @@ int phi_ref(int x) { return ret; } -vector divisors(int x) { - vector d; +vi divisors(int x) { + vi d; for (int i = 1; 1LL * i * i <= x; i++) { if (x % i) continue; d.pb(i); diff --git a/tests/8-misc/test_dp_opt.cpp b/tests/8-misc/test_dp_opt.cpp index 1c8ea3e..f9380df 100644 --- a/tests/8-misc/test_dp_opt.cpp +++ b/tests/8-misc/test_dp_opt.cpp @@ -13,7 +13,7 @@ ll rnd(ll l, ll r) { void test_cht() { int n = 200, q = 200; - vector m(n), b(n); + vl m(n), b(n); ll cur = 1000; for (int i = 0; i < n; i++) { cur -= rnd(0, 5); @@ -32,13 +32,13 @@ void test_cht() { void test_knuth() { int n = 40; - vector a(n); + vl a(n); for (int i = 0; i < n; i++) a[i] = rnd(0, 10); - vector ps(n + 1, 0); + vl ps(n + 1, 0); for (int i = 0; i < n; i++) ps[i + 1] = ps[i] + a[i]; auto cost = [&](int i, int j) { return ps[j + 1] - ps[i]; }; const ll INF = (1LL << 62); - vector> dp(n, vector(n, 0)); + vvl dp(n, vl(n, 0)); for (int len = 2; len <= n; len++) { for (int i = 0; i + len - 1 < n; i++) { int j = i + len - 1; @@ -56,7 +56,7 @@ void test_knuth() { void test_dnc() { int n = 50, k = 4; - vector base(n, 0); + vl base(n, 0); auto cost = [&](int j, int i) { ll d = i - j; return d * d; @@ -64,7 +64,7 @@ void test_dnc() { dnc_opt dc; dc.run(k, n, base, cost); const ll INF = (1LL << 62); - vector> dp(k + 1, vector(n, INF)); + vvl dp(k + 1, vl(n, INF)); dp[0] = base; for (int g = 1; g <= k; g++) { for (int i = 0; i < n; i++) { @@ -73,17 +73,17 @@ void test_dnc() { } } } - const vector &got = dc.dp(); + const vl &got = dc.dp(); for (int i = 0; i < n; i++) assert(got[i] == dp[k][i]); } -ll slope_naive(const vector &a) { +ll slope_naive(const vl &a) { int n = sz(a); ll mn = *min_element(all(a)) - n; ll mx = *max_element(all(a)) + n; int m = (int)(mx - mn + 1); const ll INF = (1LL << 62); - vector dp_prev(m, INF), dp_cur(m, INF); + vl dp_prev(m, INF), dp_cur(m, INF); for (int v = 0; v < m; v++) dp_prev[v] = llabs(a[0] - (mn + v)); for (int i = 1; i < n; i++) { ll best = INF; @@ -99,7 +99,7 @@ ll slope_naive(const vector &a) { void test_slope_trick() { for (int it = 0; it < 200; it++) { int n = (int)rnd(1, 8); - vector a(n); + vl a(n); for (int i = 0; i < n; i++) a[i] = rnd(-5, 5); assert(slope_trick(a) == slope_naive(a)); } diff --git a/tests/8-misc/test_kitamasa.cpp b/tests/8-misc/test_kitamasa.cpp index 99e832d..db7bf59 100644 --- a/tests/8-misc/test_kitamasa.cpp +++ b/tests/8-misc/test_kitamasa.cpp @@ -11,9 +11,9 @@ ll rnd(ll l, ll r) { return dis(rng); } -ll naive_rec(const vector &coef, const vector &init, ll n, ll mod) { +ll naive_rec(const vl &coef, const vl &init, ll n, ll mod) { int k = sz(coef); - vector a = init; + vl a = init; if (n < k) return mod_norm(a[n], mod); for (ll i = k; i <= n; i++) { ll v = 0; @@ -29,7 +29,7 @@ void test_random() { const ll mod = 1000000007LL; for (int it = 0; it < 200; it++) { int k = (int)rnd(1, 6); - vector coef(k), init(k); + vl coef(k), init(k); for (int i = 0; i < k; i++) { coef[i] = rnd(0, mod - 1); init[i] = rnd(0, mod - 1); diff --git a/tests/8-misc/test_lis_in_o_nlogn.cpp b/tests/8-misc/test_lis_in_o_nlogn.cpp index 5bd5a7b..56cd208 100644 --- a/tests/8-misc/test_lis_in_o_nlogn.cpp +++ b/tests/8-misc/test_lis_in_o_nlogn.cpp @@ -11,9 +11,9 @@ ll rnd(ll l, ll r) { return dis(rng); } -int lis_naive(const vector &a) { +int lis_naive(const vl &a) { int n = sz(a); - vector dp(n, 1); + vi dp(n, 1); int best = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { @@ -24,7 +24,7 @@ int lis_naive(const vector &a) { return best; } -bool is_subseq(const vector &a, const vector &b) { +bool is_subseq(const vl &a, const vl &b) { int i = 0, j = 0; while (i < sz(a) && j < sz(b)) { if (a[i] == b[j]) j++; @@ -33,7 +33,7 @@ bool is_subseq(const vector &a, const vector &b) { return j == sz(b); } -bool is_strict_inc(const vector &a) { +bool is_strict_inc(const vl &a) { for (int i = 1; i < sz(a); i++) if (a[i - 1] >= a[i]) return false; return true; @@ -42,11 +42,11 @@ bool is_strict_inc(const vector &a) { void test_random() { for (int it = 0; it < 200; it++) { int n = (int)rnd(1, 60); - vector a(n); + vl a(n); for (int i = 0; i < n; i++) a[i] = rnd(-10, 10); int exp = lis_naive(a); assert(lis_len(a) == exp); - vector seq = lis_seq(a); + vl seq = lis_seq(a); assert(sz(seq) == exp); assert(is_subseq(a, seq)); assert(is_strict_inc(seq)); diff --git a/tests/8-misc/test_simd.cpp b/tests/8-misc/test_simd.cpp index c1b7859..f2a4da9 100644 --- a/tests/8-misc/test_simd.cpp +++ b/tests/8-misc/test_simd.cpp @@ -13,7 +13,7 @@ int rnd_int(int l, int r) { void test_i32() { int n = 257; - vector a(n), b(n), c(n), d(n); + vi a(n), b(n), c(n), d(n); for (int i = 0; i < n; i++) { a[i] = rnd_int(-1000, 1000); b[i] = rnd_int(-1000, 1000); diff --git a/tests/8-misc/test_sqrt_decomposition_mos_algorithm.cpp b/tests/8-misc/test_sqrt_decomposition_mos_algorithm.cpp index 022118a..48da46b 100644 --- a/tests/8-misc/test_sqrt_decomposition_mos_algorithm.cpp +++ b/tests/8-misc/test_sqrt_decomposition_mos_algorithm.cpp @@ -13,7 +13,7 @@ int rnd_int(int l, int r) { void test_distinct() { int n = 200, qn = 200; - vector a(n); + vi a(n); for (int i = 0; i < n; i++) a[i] = rnd_int(0, 30); vector qs(qn); @@ -23,9 +23,9 @@ void test_distinct() { qs[i] = {l, r}; } - vector naive(qn, 0), ans(qn, 0); + vi naive(qn, 0), ans(qn, 0); for (int i = 0; i < qn; i++) { - vector cnt(31, 0); + vi cnt(31, 0); int cur = 0; for (int j = qs[i].fr; j <= qs[i].sc; j++) { if (cnt[a[j]]++ == 0) cur++; @@ -36,7 +36,7 @@ void test_distinct() { mo solver(n); for (int i = 0; i < qn; i++) solver.add_query(qs[i].fr, qs[i].sc, i); - vector cnt(31, 0); + vi cnt(31, 0); int cur = 0; auto add = [&](int idx) { if (cnt[a[idx]]++ == 0) cur++; diff --git a/tests/8-misc/test_system_of_difference_constraints.cpp b/tests/8-misc/test_system_of_difference_constraints.cpp index 0173ed9..b9951cd 100644 --- a/tests/8-misc/test_system_of_difference_constraints.cpp +++ b/tests/8-misc/test_system_of_difference_constraints.cpp @@ -13,7 +13,7 @@ int rnd_int(int l, int r) { bool has_neg_cycle(int n, const vector> &edges) { const ll INF = (1LL << 60); - vector> d(n, vector(n, INF)); + vvl d(n, vl(n, INF)); for (int i = 0; i < n; i++) d[i][i] = 0; for (auto [u, v, w] : edges) d[u][v] = min(d[u][v], w); for (int k = 0; k < n; k++) { @@ -48,7 +48,7 @@ void test_random() { bool neg = has_neg_cycle(n, edges); assert(ok == !neg); if (ok) { - vector x = dc.val(); + vl x = dc.val(); for (auto [u, v, w] : edges) { assert(x[v] <= x[u] + w); } From 6371eaf1d585d3320c02419d651af02fbb854541 Mon Sep 17 00:00:00 2001 From: manoflearning <77jwk0724@gmail.com> Date: Sun, 4 Jan 2026 03:17:46 +0900 Subject: [PATCH 5/6] blank --- src/1-ds/pbds.cpp | 3 --- src/4-optimizations/flow.cpp | 21 ------------------- src/5-string/aho_corasick.cpp | 4 ---- src/5-string/trie.cpp | 2 -- src/7-math/comb_binom.cpp | 2 -- src/7-math/comb_cat_der.cpp | 2 -- src/7-math/conv_fft.cpp | 1 - src/7-math/linalg_mat.cpp | 3 --- src/7-math/modint.hpp | 6 ------ src/7-math/nt_crt.cpp | 2 -- src/7-math/nt_mr_rho.cpp | 4 ---- src/7-math/nt_sieve.cpp | 7 ------- src/7-math/num.hpp | 3 --- src/8-misc/dp_opt.cpp | 3 --- src/8-misc/fraction_data_type.cpp | 3 --- src/8-misc/simd.cpp | 4 ---- .../sqrt_decomposition_mos_algorithm.cpp | 2 -- .../system_of_difference_constraints.cpp | 5 ----- 18 files changed, 77 deletions(-) diff --git a/src/1-ds/pbds.cpp b/src/1-ds/pbds.cpp index 6c0d056..f7a1ef5 100644 --- a/src/1-ds/pbds.cpp +++ b/src/1-ds/pbds.cpp @@ -20,18 +20,15 @@ void m_insert(omset &os, ll val) { // goal: insert one occurrence of val. os.insert({val, om_uid++}); } - void m_erase(omset &os, ll val) { // goal: erase one occurrence of val. auto it = os.lower_bound({val, LLONG_MIN}); os.erase(it); } - int m_order(const omset &os, ll val) { // result: number of elements strictly less than val. return os.order_of_key({val, LLONG_MIN}); } - ll m_kth(const omset &os, int k) { // result: k-th value (0-indexed) by order. return os.find_by_order(k)->fr; diff --git a/src/4-optimizations/flow.cpp b/src/4-optimizations/flow.cpp index 09ee0c9..0a4c17c 100644 --- a/src/4-optimizations/flow.cpp +++ b/src/4-optimizations/flow.cpp @@ -26,12 +26,10 @@ struct dinic { vi level, work; dinic(int n = 0) { init(n); } - void init(int n_) { n = n_; g.assign(n, {}); } - edge_ref add_edge(int u, int v, ll cap) { // goal: add forward + reverse edge edge a{v, sz(g[v]), cap}; @@ -40,13 +38,11 @@ struct dinic { g[v].pb(b); return {u, sz(g[u]) - 1}; } - ll edge_flow(edge_ref e) const { // goal: current flow on original edge const edge &ed = g[e.u][e.idx]; return g[ed.to][ed.rev].cap; } - void clear_edge(edge_ref e) { // goal: remove edge from residual graph edge &ed = g[e.u][e.idx]; @@ -72,7 +68,6 @@ struct dinic { } return level[t] != -1; } - ll dfs(int v, int t, ll f) { if (v == t || f == 0) return f; for (int &i = work[v]; i < sz(g[v]); i++) { @@ -114,7 +109,6 @@ struct hk { vi dist, match_l, match_r; hk(int n_l_ = 0, int n_r_ = 0) { init(n_l_, n_r_); } - void init(int n_l_, int n_r_) { n_l = n_l_; n_r = n_r_; @@ -123,7 +117,6 @@ struct hk { match_l.assign(n_l, -1); match_r.assign(n_r, -1); } - void add_edge(int l, int r) { // goal: add edge from left to right g[l].pb(r); @@ -155,7 +148,6 @@ struct hk { } return found; } - bool dfs(int v) { for (int r : g[v]) { int u = match_r[r]; @@ -204,12 +196,10 @@ struct mcmf { vector> g; mcmf(int n = 0) { init(n); } - void init(int n_) { n = n_; g.assign(n, {}); } - edge_ref add_edge(int u, int v, ll cap, ll cost) { // goal: add forward + reverse edge with costs edge a{v, sz(g[v]), cap, cost}; @@ -218,13 +208,11 @@ struct mcmf { g[v].pb(b); return {u, sz(g[u]) - 1}; } - ll edge_flow(edge_ref e) const { // goal: current flow on original edge const edge &ed = g[e.u][e.idx]; return g[ed.to][ed.rev].cap; } - void clear_edge(edge_ref e) { // goal: remove edge from residual graph edge &ed = g[e.u][e.idx]; @@ -264,7 +252,6 @@ struct mcmf { for (int i = 0; i < n; i++) if (d[i] < INF) pot[i] = d[i]; } - while (flow < max_f) { // goal: shortest path in reduced costs fill(all(dist), INF); @@ -328,14 +315,12 @@ struct lr_dinic { vector edges; lr_dinic(int n = 0) { init(n); } - void init(int n_) { n = n_; mf.init(n + 2); demand.assign(n, 0); edges.clear(); } - int add_edge(int u, int v, ll lo, ll hi) { // goal: store lower bounds via node demands demand[u] -= lo; @@ -343,12 +328,10 @@ struct lr_dinic { edges.pb({mf.add_edge(u, v, hi - lo), lo}); return sz(edges) - 1; } - ll edge_flow(int id) const { // goal: actual flow with lower bound restored return edges[id].lo + mf.edge_flow(edges[id].ref); } - ll add_demands(vector &aux) { // goal: connect ss/tt for feasible circulation ll total = 0; @@ -415,7 +398,6 @@ struct lr_mcmf { ll base_cost; lr_mcmf(int n = 0) { init(n); } - void init(int n_) { n = n_; mf.init(n + 2); @@ -423,7 +405,6 @@ struct lr_mcmf { edges.clear(); base_cost = 0; } - int add_edge(int u, int v, ll lo, ll hi, ll cost) { // goal: store lower bounds via node demands demand[u] -= lo; @@ -432,12 +413,10 @@ struct lr_mcmf { edges.pb({mf.add_edge(u, v, hi - lo, cost), lo}); return sz(edges) - 1; } - ll edge_flow(int id) const { // goal: actual flow with lower bound restored return edges[id].lo + mf.edge_flow(edges[id].ref); } - ll add_demands(vector &aux) { // goal: connect ss/tt for feasible circulation ll total = 0; diff --git a/src/5-string/aho_corasick.cpp b/src/5-string/aho_corasick.cpp index 6e28bd5..e935927 100644 --- a/src/5-string/aho_corasick.cpp +++ b/src/5-string/aho_corasick.cpp @@ -10,7 +10,6 @@ struct aho_corasick { vi fail, out; aho_corasick() { init(); } - void init() { // goal: reset to a single root node. nxt.assign(1, {}); @@ -18,7 +17,6 @@ struct aho_corasick { fail.assign(1, 0); out.assign(1, 0); } - int add(const string &s) { // goal: insert a pattern and return its terminal node. int v = 0; @@ -66,7 +64,6 @@ struct aho_corasick { } int step(int v, char ch) const { return nxt[v][ch - 'a']; } - bool match_any(const string &t) const { // result: true if any pattern appears in t. int v = 0; @@ -76,7 +73,6 @@ struct aho_corasick { } return false; } - ll count(const string &t) const { // result: total number of pattern occurrences in t. ll res = 0; diff --git a/src/5-string/trie.cpp b/src/5-string/trie.cpp index ad652db..723470e 100644 --- a/src/5-string/trie.cpp +++ b/src/5-string/trie.cpp @@ -10,14 +10,12 @@ struct trie { vector term; trie() { init(); } - void init() { // goal: reset to empty trie. nxt.assign(1, {}); nxt[0].fill(-1); term.assign(1, 0); } - int add(const string &s) { // goal: insert a string and mark its terminal node. int v = 0; diff --git a/src/7-math/comb_binom.cpp b/src/7-math/comb_binom.cpp index 18add67..4044de6 100644 --- a/src/7-math/comb_binom.cpp +++ b/src/7-math/comb_binom.cpp @@ -34,7 +34,6 @@ struct comb_dp { for (int j = 1; j < i; j++) dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]; } } - ll ncr(int n_, int r) const { if (r < 0 || n_ < r || n_ > n) return 0; return dp[n_][r]; @@ -60,7 +59,6 @@ struct comb_mod { ifac[n] = pow_mod(fac[n], mod - 2, mod); for (int i = n; i >= 1; i--) ifac[i - 1] = (ll)((__int128)ifac[i] * i % mod); } - ll ncr(int n_, int r) const { if (r < 0 || n_ < r || n_ > n) return 0; ll ret = (ll)((__int128)fac[n_] * ifac[r] % mod); diff --git a/src/7-math/comb_cat_der.cpp b/src/7-math/comb_cat_der.cpp index d6b49a9..ae93d11 100644 --- a/src/7-math/comb_cat_der.cpp +++ b/src/7-math/comb_cat_der.cpp @@ -14,7 +14,6 @@ struct catalan_mod { mod = mod_; cb.init(2 * n, mod); } - ll catalan(int n) const { ll ret = cb.ncr(2 * n, n); ll inv = euclid::inv_mod(n + 1, mod); @@ -42,6 +41,5 @@ struct derange_mod { dp[i] = (ll)((__int128)(i - 1) * sum % mod); } } - ll get(int n) const { return dp[n]; } }; diff --git a/src/7-math/conv_fft.cpp b/src/7-math/conv_fft.cpp index 4f6434e..671cf6b 100644 --- a/src/7-math/conv_fft.cpp +++ b/src/7-math/conv_fft.cpp @@ -100,7 +100,6 @@ struct ntt_mod { if (x < 0) x += MOD; return x; } - static ll mod_pow(ll b, ll e) { ll ans = 1; while (e) { diff --git a/src/7-math/linalg_mat.cpp b/src/7-math/linalg_mat.cpp index 1bd446a..c886336 100644 --- a/src/7-math/linalg_mat.cpp +++ b/src/7-math/linalg_mat.cpp @@ -10,13 +10,11 @@ struct matrix { vvl a; matrix(int n = 0, int m = 0, ll mod_ = 1) : mod(mod_), a(n, vl(m, 0)) {} - static matrix ident(int n, ll mod) { matrix r(n, n, mod); for (int i = 0; i < n; i++) r.a[i][i] = 1 % mod; return r; } - matrix operator*(const matrix &o) const { int n = sz(a); int m = sz(o.a[0]); @@ -34,7 +32,6 @@ struct matrix { } return r; } - static matrix power(matrix base, ll exp) { // goal: fast exponentiation. matrix res = ident(sz(base.a), base.mod); diff --git a/src/7-math/modint.hpp b/src/7-math/modint.hpp index 16612cd..f82c697 100644 --- a/src/7-math/modint.hpp +++ b/src/7-math/modint.hpp @@ -21,7 +21,6 @@ struct modint { modint(ll x = 0) : v(norm(x)) {} static ll mod() { return MOD; } - modint &operator+=(const modint &o) { v += o.v; if (v >= MOD) v -= MOD; @@ -39,7 +38,6 @@ struct modint { modint &operator/=(const modint &o) { return (*this) *= o.inv(); } modint operator-() const { return modint(v ? MOD - v : 0); } - friend modint operator+(modint a, const modint &b) { return a += b; } friend modint operator-(modint a, const modint &b) { return a -= b; } friend modint operator*(modint a, const modint &b) { return a *= b; } @@ -52,7 +50,6 @@ struct modint { modint inv() const { return euclid::inv_mod(v, MOD); } explicit operator ll() const { return v; } - friend ostream &operator<<(ostream &os, const modint &x) { return os << x.v; } friend istream &operator>>(istream &is, modint &x) { ll t; @@ -82,7 +79,6 @@ struct dyn_modint { dyn_modint(ll x = 0) : v(norm(x)) {} static void set_mod(ll m) { mod_ = m; } static ll mod() { return mod_; } - dyn_modint &operator+=(const dyn_modint &o) { v += o.v; if (v >= mod_) v -= mod_; @@ -100,7 +96,6 @@ struct dyn_modint { dyn_modint &operator/=(const dyn_modint &o) { return (*this) *= o.inv(); } dyn_modint operator-() const { return dyn_modint(v ? mod_ - v : 0); } - friend dyn_modint operator+(dyn_modint a, const dyn_modint &b) { return a += b; } friend dyn_modint operator-(dyn_modint a, const dyn_modint &b) { return a -= b; } friend dyn_modint operator*(dyn_modint a, const dyn_modint &b) { return a *= b; } @@ -113,7 +108,6 @@ struct dyn_modint { dyn_modint inv() const { return euclid::inv_mod(v, mod_); } explicit operator ll() const { return v; } - friend ostream &operator<<(ostream &os, const dyn_modint &x) { return os << x.v; } friend istream &operator>>(istream &is, dyn_modint &x) { ll t; diff --git a/src/7-math/nt_crt.cpp b/src/7-math/nt_crt.cpp index b368a98..af594f4 100644 --- a/src/7-math/nt_crt.cpp +++ b/src/7-math/nt_crt.cpp @@ -13,7 +13,6 @@ struct crt { if (a.fr < 0) a.fr += a.sc; return a; } - static pll merge(pll a, pll b) { // result: x = ret.fr (mod ret.sc), or {-1,-1} if no solution. a = norm(a); @@ -39,7 +38,6 @@ struct crt { if (r < 0) r += l; return {r, l}; } - static pll merge_all(const vector &cs) { pll cur = {0, 1}; for (auto c : cs) cur = merge(cur, c); diff --git a/src/7-math/nt_mr_rho.cpp b/src/7-math/nt_mr_rho.cpp index fb00038..f4f7eb0 100644 --- a/src/7-math/nt_mr_rho.cpp +++ b/src/7-math/nt_mr_rho.cpp @@ -8,7 +8,6 @@ struct miller_rabin { static ll mul(ll a, ll b, ll mod) { return (ll)((__int128)a * b % mod); } static ll pow_mod(ll a, ll e, ll mod) { return ::pow_mod(a, e, mod); } - static bool is_prime(ll n) { if (n < 2) return 0; for (ll p : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}) { @@ -43,7 +42,6 @@ struct miller_rabin { // usage: auto f=pollard_rho::factor(n); struct pollard_rho { static ll f(ll x, ll c, ll mod) { return (miller_rabin::mul(x, x, mod) + c) % mod; } - static ll rho(ll n) { if ((n & 1) == 0) return 2; static mt19937_64 rng(712367); @@ -59,7 +57,6 @@ struct pollard_rho { if (d != n) return d; } } - static void rec(ll n, vl &out) { if (n == 1) return; if (miller_rabin::is_prime(n)) { @@ -70,7 +67,6 @@ struct pollard_rho { rec(d, out); rec(n / d, out); } - static vl factor(ll n) { // result: prime factors of |n| with repetition, sorted. vl out; diff --git a/src/7-math/nt_sieve.cpp b/src/7-math/nt_sieve.cpp index 5dc8d75..d2d2a47 100644 --- a/src/7-math/nt_sieve.cpp +++ b/src/7-math/nt_sieve.cpp @@ -13,7 +13,6 @@ struct era_sieve { era_sieve(int n_ = 0) { if (n_ >= 0) init(n_); } - void init(int n_) { // goal: build isp/primes for [0..n] n = n_; @@ -30,7 +29,6 @@ struct era_sieve { for (int i = 3; i <= n; i += 2) if (isp[i]) primes.pb(i); } - bool is_prime(int x) const { return x >= 2 && x <= n && isp[x]; } }; @@ -45,7 +43,6 @@ struct lin_sieve { lin_sieve(int n_ = 0) { if (n_ >= 0) init(n_); } - void init(int n_) { // goal: fill lp/primes/mu/phi for [0..n] n = n_; @@ -75,9 +72,7 @@ struct lin_sieve { } } } - bool is_prime(int x) const { return x >= 2 && x <= n && lp[x] == x; } - vi factor(int x) const { // result: prime factors of x (with repetition), in nondecreasing order vi ret; @@ -88,7 +83,6 @@ struct lin_sieve { } return ret; } - vector factor_cnt(int x) const { // result: {{p, e}} s.t. x = prod p^e, increasing p vector ret; @@ -128,7 +122,6 @@ struct euler_phi { if (x > 1) ret = ret / x * (x - 1); return ret; } - static vi phi_upto(int n) { lin_sieve sv(n); return sv.phi; diff --git a/src/7-math/num.hpp b/src/7-math/num.hpp index e2ebe6d..e0456a9 100644 --- a/src/7-math/num.hpp +++ b/src/7-math/num.hpp @@ -23,7 +23,6 @@ struct euclid { if (v < 0) v = -v; return v; } - static pair egcd(ll a, ll b) { // result: {{x, y}, g} s.t. a*x + b*y = g = gcd(a, b) ll s = 0, os = 1; @@ -48,7 +47,6 @@ struct euclid { } return {{os, ot}, orr}; } - static ll inv_mod(ll a, ll mod) { // result: x in [0, mod) s.t. a*x = 1 (mod mod), or -1 if not invertible. a %= mod; @@ -59,7 +57,6 @@ struct euclid { if (x < 0) x += mod; return x; } - static ll lin_cong(ll a, ll b, ll mod) { // what: solve linear congruence a*x = b (mod mod). // result: one x in [0, mod) if exists, else -1. diff --git a/src/8-misc/dp_opt.cpp b/src/8-misc/dp_opt.cpp index c37dca5..ed1b76a 100644 --- a/src/8-misc/dp_opt.cpp +++ b/src/8-misc/dp_opt.cpp @@ -21,7 +21,6 @@ struct cht_mono { ld isect(const line &a, const line &b) const { return (ld)(b.b - a.b) / (a.m - b.m); } - void add_line(ll m, ll b) { // goal: maintain lower hull with decreasing slopes if (!st.empty() && st.back().m == m) { @@ -37,7 +36,6 @@ struct cht_mono { if (st.empty()) cur.x = NEG_INF; st.pb(cur); } - ll get(ll x) const { // invariant: st is sorted by x; pick last with x_i <= x int l = 0, r = sz(st) - 1; @@ -109,7 +107,6 @@ struct dnc_opt { prv.swap(cur); } } - const vl &dp() const { return prv; } template diff --git a/src/8-misc/fraction_data_type.cpp b/src/8-misc/fraction_data_type.cpp index f19882e..3d9f6b6 100644 --- a/src/8-misc/fraction_data_type.cpp +++ b/src/8-misc/fraction_data_type.cpp @@ -8,7 +8,6 @@ struct fraction { ll n, d; fraction(ll n_ = 0, ll d_ = 1) { set(n_, d_); } - static ll gcd_ll(ll a, ll b) { if (a < 0) a = -a; if (b < 0) b = -b; @@ -19,14 +18,12 @@ struct fraction { } return a; } - void set(ll n_, ll d_) { // goal: normalize sign + reduce n = n_; d = d_; norm(); } - void norm() { if (d < 0) n = -n, d = -d; ll g = gcd_ll(n, d); diff --git a/src/8-misc/simd.cpp b/src/8-misc/simd.cpp index 8408fc4..d7600bb 100644 --- a/src/8-misc/simd.cpp +++ b/src/8-misc/simd.cpp @@ -19,7 +19,6 @@ struct simd_i32 { } for (; i < n; i++) c[i] = a[i] + b[i]; } - static ll sum(const int *a, int n) { // goal: sum all values with 64-bit accumulation int i = 0; @@ -40,7 +39,6 @@ struct simd_i32 { for (; i < n; i++) res += a[i]; return res; } - static int range_min(const int *a, int l, int r) { // goal: min in [l, r] int i = l; @@ -56,7 +54,6 @@ struct simd_i32 { for (; i <= r; i++) res = min(res, a[i]); return res; } - static int count_eq(const int *a, int n, int v) { // goal: count occurrences of v int i = 0; @@ -84,7 +81,6 @@ struct simd_f32 { } for (; i < n; i++) a[i] += b[i]; } - static float dot(const float *a, const float *b, int n) { // goal: dot product int i = 0; diff --git a/src/8-misc/sqrt_decomposition_mos_algorithm.cpp b/src/8-misc/sqrt_decomposition_mos_algorithm.cpp index 684f55c..cdfeac5 100644 --- a/src/8-misc/sqrt_decomposition_mos_algorithm.cpp +++ b/src/8-misc/sqrt_decomposition_mos_algorithm.cpp @@ -13,14 +13,12 @@ struct mo { vector q; mo(int n_ = 0) { init(n_); } - void init(int n_) { // goal: set array size and reset queries. n = n_; bs = max(1, (int)sqrt(n)); q.clear(); } - void add_query(int l, int r, int idx) { q.pb({l, r, idx}); } template diff --git a/src/8-misc/system_of_difference_constraints.cpp b/src/8-misc/system_of_difference_constraints.cpp index 3071a1e..7820813 100644 --- a/src/8-misc/system_of_difference_constraints.cpp +++ b/src/8-misc/system_of_difference_constraints.cpp @@ -15,23 +15,19 @@ struct diff_cons { vl dist; diff_cons(int n_ = 0) { init(n_); } - void init(int n_) { n = n_; g.assign(n, {}); dist.assign(n, 0); } - void add_le(int u, int v, ll w) { // goal: x_v - x_u <= w g[u].pb({v, w}); } - void add_ge(int u, int v, ll w) { // goal: x_v - x_u >= w <=> x_u - x_v <= -w add_le(v, u, -w); } - void add_eq(int u, int v, ll w) { // goal: x_v - x_u = w add_le(u, v, w); @@ -60,6 +56,5 @@ struct diff_cons { } return true; } - vl val() const { return dist; } }; From 18167379ac80730fc8df75199840be40510b92bd Mon Sep 17 00:00:00 2001 From: manoflearning <77jwk0724@gmail.com> Date: Sun, 4 Jan 2026 03:33:38 +0900 Subject: [PATCH 6/6] common --- README.md | 4 ++-- src/{common => 0-common}/common.hpp | 0 src/1-ds/erasable_pq.cpp | 2 +- src/1-ds/fenwick_tree.cpp | 2 +- src/1-ds/li_chao_tree.cpp | 2 +- src/1-ds/merge_sort_tree.cpp | 2 +- src/1-ds/pbds.cpp | 2 +- src/1-ds/segment_tree.cpp | 2 +- src/1-ds/union_find.cpp | 2 +- src/2-graph/bcc.cpp | 2 +- src/2-graph/euler_circuit.cpp | 2 +- src/2-graph/kth_shortest_path.cpp | 2 +- src/2-graph/offline_dynamic_connectivity.cpp | 2 +- src/2-graph/scc_2_sat.cpp | 2 +- src/2-graph/shortest_path.cpp | 2 +- src/3-tree/centroid_decomp.cpp | 2 +- src/3-tree/lca_sparse_table.cpp | 2 +- src/3-tree/tree_composition.cpp | 2 +- src/3-tree/tree_exchange_argument.cpp | 2 +- src/4-optimizations/flow.cpp | 6 +----- src/4-optimizations/hungarian.cpp | 2 +- src/5-string/aho_corasick.cpp | 3 +-- src/5-string/kmp_algorithm.cpp | 2 +- src/5-string/manachers_algorithm.cpp | 2 +- src/5-string/rabin_karp_algorithm.cpp | 3 +-- src/5-string/suffix_array.cpp | 2 +- src/5-string/trie.cpp | 3 +-- src/5-string/z_algorithm.cpp | 2 +- src/6-geometry/geom_base.cpp | 2 +- src/7-math/conv_fft.cpp | 2 +- src/7-math/linalg_mat.cpp | 2 +- src/7-math/misc_sqrt.cpp | 2 +- src/7-math/modint.hpp | 8 -------- src/7-math/nt_sieve.cpp | 2 +- src/7-math/num.hpp | 2 +- src/8-misc/dp_opt.cpp | 2 +- src/8-misc/fraction_data_type.cpp | 3 +-- src/8-misc/kitamasa.cpp | 2 +- src/8-misc/lis_in_o_nlogn.cpp | 2 +- src/8-misc/random.cpp | 2 +- src/8-misc/simd.cpp | 2 +- src/8-misc/sqrt_decomposition_mos_algorithm.cpp | 3 +-- src/8-misc/system_of_difference_constraints.cpp | 2 +- src/8-misc/ternary_search.cpp | 2 +- 44 files changed, 43 insertions(+), 60 deletions(-) rename src/{common => 0-common}/common.hpp (100%) diff --git a/README.md b/README.md index 574e904..5741a94 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ My implementations of various data structures and algorithms for competitive programming. ## Contents (GitHub links, `main`) +- [0-common](https://github.com/manoflearning/cp-reference-codes/tree/main/src/0-common) + - [`common.hpp`](https://github.com/manoflearning/cp-reference-codes/blob/main/src/0-common/common.hpp) - [1-ds](https://github.com/manoflearning/cp-reference-codes/tree/main/src/1-ds) - [`erasable_pq.cpp`](https://github.com/manoflearning/cp-reference-codes/blob/main/src/1-ds/erasable_pq.cpp) - [`fenwick_tree.cpp`](https://github.com/manoflearning/cp-reference-codes/blob/main/src/1-ds/fenwick_tree.cpp) @@ -69,5 +71,3 @@ My implementations of various data structures and algorithms for competitive pro - [`stress_test.py`](https://github.com/manoflearning/cp-reference-codes/blob/main/src/8-misc/stress_test.py) - [`system_of_difference_constraints.cpp`](https://github.com/manoflearning/cp-reference-codes/blob/main/src/8-misc/system_of_difference_constraints.cpp) - [`ternary_search.cpp`](https://github.com/manoflearning/cp-reference-codes/blob/main/src/8-misc/ternary_search.cpp) -- [common](https://github.com/manoflearning/cp-reference-codes/tree/main/src/common) - - [`common.hpp`](https://github.com/manoflearning/cp-reference-codes/blob/main/src/common/common.hpp) diff --git a/src/common/common.hpp b/src/0-common/common.hpp similarity index 100% rename from src/common/common.hpp rename to src/0-common/common.hpp diff --git a/src/1-ds/erasable_pq.cpp b/src/1-ds/erasable_pq.cpp index 10f972e..bec5c49 100644 --- a/src/1-ds/erasable_pq.cpp +++ b/src/1-ds/erasable_pq.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: priority queue that supports deleting arbitrary values via lazy deletion. // time: push/pop/erase O(log n); memory: O(n) diff --git a/src/1-ds/fenwick_tree.cpp b/src/1-ds/fenwick_tree.cpp index cbdf86a..0dd3f3c 100644 --- a/src/1-ds/fenwick_tree.cpp +++ b/src/1-ds/fenwick_tree.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: maintain prefix sums with point updates and range sum queries. // time: build O(n), update/query O(log n); memory: O(n) diff --git a/src/1-ds/li_chao_tree.cpp b/src/1-ds/li_chao_tree.cpp index 9b498c8..3e3ffce 100644 --- a/src/1-ds/li_chao_tree.cpp +++ b/src/1-ds/li_chao_tree.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: maintain max of lines on a fixed x-range with online add + point query. // time: add/query O(log X); memory: O(n) diff --git a/src/1-ds/merge_sort_tree.cpp b/src/1-ds/merge_sort_tree.cpp index 2f9f3b7..e3f3f61 100644 --- a/src/1-ds/merge_sort_tree.cpp +++ b/src/1-ds/merge_sort_tree.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" constexpr int MAX_MST = 1 << 17; // what: static range count queries by storing sorted lists on a segment tree. diff --git a/src/1-ds/pbds.cpp b/src/1-ds/pbds.cpp index f7a1ef5..2fae294 100644 --- a/src/1-ds/pbds.cpp +++ b/src/1-ds/pbds.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" #include #include using namespace __gnu_pbds; diff --git a/src/1-ds/segment_tree.cpp b/src/1-ds/segment_tree.cpp index 06d0775..760e9fc 100644 --- a/src/1-ds/segment_tree.cpp +++ b/src/1-ds/segment_tree.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: point update + range sum on a fixed-size array using a tree. // time: build O(n), update/query O(log n); memory: O(n) diff --git a/src/1-ds/union_find.cpp b/src/1-ds/union_find.cpp index e8355bc..aca213c 100644 --- a/src/1-ds/union_find.cpp +++ b/src/1-ds/union_find.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: maintain dynamic connectivity with union-find and size queries. // time: init O(n), join/find amortized a(n); memory: O(n) diff --git a/src/2-graph/bcc.cpp b/src/2-graph/bcc.cpp index c7ce283..376ea63 100644 --- a/src/2-graph/bcc.cpp +++ b/src/2-graph/bcc.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: find biconnected components and articulation points/bridges in an undirected graph. // time: O(n+m); memory: O(n+m) diff --git a/src/2-graph/euler_circuit.cpp b/src/2-graph/euler_circuit.cpp index 7552b2f..9f67492 100644 --- a/src/2-graph/euler_circuit.cpp +++ b/src/2-graph/euler_circuit.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: build an Eulerian circuit in an undirected multigraph (adjacency matrix). // time: O(n^2+m); memory: O(n^2) diff --git a/src/2-graph/kth_shortest_path.cpp b/src/2-graph/kth_shortest_path.cpp index 4986635..69bc605 100644 --- a/src/2-graph/kth_shortest_path.cpp +++ b/src/2-graph/kth_shortest_path.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: enumerate k-th shortest walk from s to t with non-negative weights (Eppstein-style). // time: O((n+m)log m + klog k); memory: O(n+m+heap) diff --git a/src/2-graph/offline_dynamic_connectivity.cpp b/src/2-graph/offline_dynamic_connectivity.cpp index a875c73..75a7270 100644 --- a/src/2-graph/offline_dynamic_connectivity.cpp +++ b/src/2-graph/offline_dynamic_connectivity.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: answer edge add/remove connectivity queries offline using segment tree + rollback DSU. // time: O((n+q)log q); memory: O(n+q) diff --git a/src/2-graph/scc_2_sat.cpp b/src/2-graph/scc_2_sat.cpp index bf0e64d..fa036e4 100644 --- a/src/2-graph/scc_2_sat.cpp +++ b/src/2-graph/scc_2_sat.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: compute SCCs in a directed graph using Kosaraju's algorithm. // time: O(n+m); memory: O(n+m) diff --git a/src/2-graph/shortest_path.cpp b/src/2-graph/shortest_path.cpp index c929df3..918118a 100644 --- a/src/2-graph/shortest_path.cpp +++ b/src/2-graph/shortest_path.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: compute single-source shortest paths with non-negative edges (Dijkstra). // time: O((n+m)log n); memory: O(n+m) diff --git a/src/3-tree/centroid_decomp.cpp b/src/3-tree/centroid_decomp.cpp index c58f79b..a773275 100644 --- a/src/3-tree/centroid_decomp.cpp +++ b/src/3-tree/centroid_decomp.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: centroid decomposition for tree, builds centroid parent/children for path queries. // time: O(n log n); memory: O(n) diff --git a/src/3-tree/lca_sparse_table.cpp b/src/3-tree/lca_sparse_table.cpp index f9ebd7c..eb73f14 100644 --- a/src/3-tree/lca_sparse_table.cpp +++ b/src/3-tree/lca_sparse_table.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: LCA via binary lifting for rooted tree. // time: build O(n log n), query O(log n); memory: O(n log n) diff --git a/src/3-tree/tree_composition.cpp b/src/3-tree/tree_composition.cpp index b599728..a252db8 100644 --- a/src/3-tree/tree_composition.cpp +++ b/src/3-tree/tree_composition.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: virtual tree builder for subset DP using LCA and dfs order. // time: build O(n log n), make O(k log k); memory: O(n log n) diff --git a/src/3-tree/tree_exchange_argument.cpp b/src/3-tree/tree_exchange_argument.cpp index 005f6c3..dd673a9 100644 --- a/src/3-tree/tree_exchange_argument.cpp +++ b/src/3-tree/tree_exchange_argument.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: maximize sum w[i]*completion_time[i] under precedence "parent before child" on rooted tree. // time: O(n log n); memory: O(n) diff --git a/src/4-optimizations/flow.cpp b/src/4-optimizations/flow.cpp index 0a4c17c..781ee85 100644 --- a/src/4-optimizations/flow.cpp +++ b/src/4-optimizations/flow.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: collection of flow solvers (max flow, min-cost flow, matching, bounds). // time: see each struct; memory: O(E) @@ -82,7 +82,6 @@ struct dinic { } return 0; } - ll max_flow(int s, int t, ll limit = INF) { if (s == t) return 0; // edge: no flow needed ll flow = 0; @@ -160,7 +159,6 @@ struct hk { dist[v] = -1; return false; } - int max_matching() { // goal: compute maximum matching size fill(all(match_l), -1); @@ -356,7 +354,6 @@ struct lr_dinic { for (auto ref : aux) mf.clear_edge(ref); return flow == total; } - pair max_flow(int s, int t) { if (s == t) return {feasible(), 0}; // edge: trivial s == t vector aux; @@ -442,7 +439,6 @@ struct lr_mcmf { if (res.fr != total) return {false, 0}; return {true, res.sc + base_cost}; } - pair max_flow(int s, int t, bool init_pot = true) { if (s == t) { auto r = feasible(init_pot); diff --git a/src/4-optimizations/hungarian.cpp b/src/4-optimizations/hungarian.cpp index 2339241..fa438ca 100644 --- a/src/4-optimizations/hungarian.cpp +++ b/src/4-optimizations/hungarian.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: solve rectangular assignment problem (min-cost matching) via Hungarian. // time: O(n m^2); memory: O(n+m) diff --git a/src/5-string/aho_corasick.cpp b/src/5-string/aho_corasick.cpp index e935927..c90a738 100644 --- a/src/5-string/aho_corasick.cpp +++ b/src/5-string/aho_corasick.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: build automaton to find many lowercase patterns inside a text. // time: add O(|p|), build O(nodes*ALPHA), query O(|t|); memory: O(nodes*ALPHA) @@ -34,7 +34,6 @@ struct aho_corasick { out[v]++; return v; } - void build() { // goal: compute failure links and output counts. queue q; diff --git a/src/5-string/kmp_algorithm.cpp b/src/5-string/kmp_algorithm.cpp index ad167d3..876fb25 100644 --- a/src/5-string/kmp_algorithm.cpp +++ b/src/5-string/kmp_algorithm.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: find all occurrences of a pattern using prefix-function (KMP). // time: O(|t|+|p|); memory: O(|p|) diff --git a/src/5-string/manachers_algorithm.cpp b/src/5-string/manachers_algorithm.cpp index d728426..c8e1a9b 100644 --- a/src/5-string/manachers_algorithm.cpp +++ b/src/5-string/manachers_algorithm.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: compute longest palindrome radius at every center (odd/even). // time: O(n); memory: O(n) diff --git a/src/5-string/rabin_karp_algorithm.cpp b/src/5-string/rabin_karp_algorithm.cpp index 66974ed..4e94dcf 100644 --- a/src/5-string/rabin_karp_algorithm.cpp +++ b/src/5-string/rabin_karp_algorithm.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: probabilistic substring matching using double rolling hash. // time: build O(n), get O(1), match O(n); memory: O(n) @@ -25,7 +25,6 @@ struct rabin_karp { h2[i + 1] = (h2[i] * BASE + x) % MOD2; } } - pll get(int l, int r) const { // [l, r) // result: hash of s[l..r). ll x1 = (h1[r] - h1[l] * p1[r - l]) % MOD1; diff --git a/src/5-string/suffix_array.cpp b/src/5-string/suffix_array.cpp index 10257f5..5852516 100644 --- a/src/5-string/suffix_array.cpp +++ b/src/5-string/suffix_array.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: build lexicographic suffix order and LCP for fast substring comparisons. // time: build_sa O(n log n), build_lcp O(n); memory: O(n) diff --git a/src/5-string/trie.cpp b/src/5-string/trie.cpp index 723470e..a274f21 100644 --- a/src/5-string/trie.cpp +++ b/src/5-string/trie.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: store a set of lowercase strings for fast prefix traversal and lookup. // time: add/has O(|s|); memory: O(nodes*ALPHA) @@ -32,7 +32,6 @@ struct trie { term[v] = 1; return v; } - bool has(const string &s) const { // result: true if s exists as a full word. int v = 0; diff --git a/src/5-string/z_algorithm.cpp b/src/5-string/z_algorithm.cpp index 7ae1048..0eb8cd6 100644 --- a/src/5-string/z_algorithm.cpp +++ b/src/5-string/z_algorithm.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: compute prefix match lengths for each position in a string. // time: O(n); memory: O(n) diff --git a/src/6-geometry/geom_base.cpp b/src/6-geometry/geom_base.cpp index 85fb905..eb6bc47 100644 --- a/src/6-geometry/geom_base.cpp +++ b/src/6-geometry/geom_base.cpp @@ -1,5 +1,5 @@ #pragma once -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: 2D primitives and orientation/intersection helpers for integer and double points. // time: O(1) per op; memory: O(1) diff --git a/src/7-math/conv_fft.cpp b/src/7-math/conv_fft.cpp index 671cf6b..f8fdefd 100644 --- a/src/7-math/conv_fft.cpp +++ b/src/7-math/conv_fft.cpp @@ -1,5 +1,5 @@ #pragma once -#include "../common/common.hpp" +#include "../0-common/common.hpp" #include "num.hpp" // what: multiply integer sequences using FFT (optionally via split for mod). diff --git a/src/7-math/linalg_mat.cpp b/src/7-math/linalg_mat.cpp index c886336..c136edc 100644 --- a/src/7-math/linalg_mat.cpp +++ b/src/7-math/linalg_mat.cpp @@ -1,5 +1,5 @@ #pragma once -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: small matrix helper for modular multiply and fast exponentiation. // time: multiply O(n*m*k); power O(log e * n^3); memory: O(n*m) diff --git a/src/7-math/misc_sqrt.cpp b/src/7-math/misc_sqrt.cpp index 8a96a0b..1a7c7de 100644 --- a/src/7-math/misc_sqrt.cpp +++ b/src/7-math/misc_sqrt.cpp @@ -1,5 +1,5 @@ #pragma once -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: list all divisors and prime factors of a single integer by sqrt trial division. // time: O(sqrt x); memory: O(1) extra diff --git a/src/7-math/modint.hpp b/src/7-math/modint.hpp index f82c697..04eba61 100644 --- a/src/7-math/modint.hpp +++ b/src/7-math/modint.hpp @@ -18,7 +18,6 @@ struct modint { return x; } static ll mul(ll a, ll b) { return (ll)((__int128)a * b % MOD); } - modint(ll x = 0) : v(norm(x)) {} static ll mod() { return MOD; } modint &operator+=(const modint &o) { @@ -36,7 +35,6 @@ struct modint { return *this; } modint &operator/=(const modint &o) { return (*this) *= o.inv(); } - modint operator-() const { return modint(v ? MOD - v : 0); } friend modint operator+(modint a, const modint &b) { return a += b; } friend modint operator-(modint a, const modint &b) { return a -= b; } @@ -45,10 +43,8 @@ struct modint { bool operator==(const modint &o) const { return v == o.v; } bool operator!=(const modint &o) const { return v != o.v; } - modint pow(ll e) const { return pow_mod(v, e, MOD); } modint inv() const { return euclid::inv_mod(v, MOD); } - explicit operator ll() const { return v; } friend ostream &operator<<(ostream &os, const modint &x) { return os << x.v; } friend istream &operator>>(istream &is, modint &x) { @@ -75,7 +71,6 @@ struct dyn_modint { return x; } static ll mul(ll a, ll b) { return (ll)((__int128)a * b % mod_); } - dyn_modint(ll x = 0) : v(norm(x)) {} static void set_mod(ll m) { mod_ = m; } static ll mod() { return mod_; } @@ -94,7 +89,6 @@ struct dyn_modint { return *this; } dyn_modint &operator/=(const dyn_modint &o) { return (*this) *= o.inv(); } - dyn_modint operator-() const { return dyn_modint(v ? mod_ - v : 0); } friend dyn_modint operator+(dyn_modint a, const dyn_modint &b) { return a += b; } friend dyn_modint operator-(dyn_modint a, const dyn_modint &b) { return a -= b; } @@ -103,10 +97,8 @@ struct dyn_modint { bool operator==(const dyn_modint &o) const { return v == o.v; } bool operator!=(const dyn_modint &o) const { return v != o.v; } - dyn_modint pow(ll e) const { return pow_mod(v, e, mod_); } dyn_modint inv() const { return euclid::inv_mod(v, mod_); } - explicit operator ll() const { return v; } friend ostream &operator<<(ostream &os, const dyn_modint &x) { return os << x.v; } friend istream &operator>>(istream &is, dyn_modint &x) { diff --git a/src/7-math/nt_sieve.cpp b/src/7-math/nt_sieve.cpp index d2d2a47..3883342 100644 --- a/src/7-math/nt_sieve.cpp +++ b/src/7-math/nt_sieve.cpp @@ -1,5 +1,5 @@ #pragma once -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: precompute primality table and prime list with Eratosthenes sieve. // time: O(n log log n); memory: O(n) diff --git a/src/7-math/num.hpp b/src/7-math/num.hpp index e0456a9..054b77d 100644 --- a/src/7-math/num.hpp +++ b/src/7-math/num.hpp @@ -1,6 +1,6 @@ #pragma once -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: gcd/egcd/inverse helpers and modular exponentiation. // time: O(log n); memory: O(1) diff --git a/src/8-misc/dp_opt.cpp b/src/8-misc/dp_opt.cpp index ed1b76a..96d02b4 100644 --- a/src/8-misc/dp_opt.cpp +++ b/src/8-misc/dp_opt.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: collection of DP optimizations (CHT, Knuth, DnC, slope trick). // time: see each component; memory: see each component. diff --git a/src/8-misc/fraction_data_type.cpp b/src/8-misc/fraction_data_type.cpp index 3d9f6b6..fa93f51 100644 --- a/src/8-misc/fraction_data_type.cpp +++ b/src/8-misc/fraction_data_type.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: normalized rational type with exact arithmetic and comparisons. // time: O(log max(|n|,|d|)) per op; memory: O(1) @@ -38,7 +38,6 @@ struct fraction { bool operator>(const fraction &rhs) const { return rhs < *this; } bool operator<=(const fraction &rhs) const { return !(rhs < *this); } bool operator>=(const fraction &rhs) const { return !(*this < rhs); } - fraction operator+(const fraction &rhs) const { fraction ret; ret.n = n * rhs.d + rhs.n * d; diff --git a/src/8-misc/kitamasa.cpp b/src/8-misc/kitamasa.cpp index a095943..edc5a77 100644 --- a/src/8-misc/kitamasa.cpp +++ b/src/8-misc/kitamasa.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: compute n-th term of a linear recurrence using Kitamasa. // time: O(k^2 log n); memory: O(k^2) diff --git a/src/8-misc/lis_in_o_nlogn.cpp b/src/8-misc/lis_in_o_nlogn.cpp index 9e35eef..84ad0a6 100644 --- a/src/8-misc/lis_in_o_nlogn.cpp +++ b/src/8-misc/lis_in_o_nlogn.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: compute LIS length and reconstruct one increasing subsequence. // time: O(n log n); memory: O(n) diff --git a/src/8-misc/random.cpp b/src/8-misc/random.cpp index 12700bd..56b0bb9 100644 --- a/src/8-misc/random.cpp +++ b/src/8-misc/random.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: mt19937_64 quick usage snippet (time-seeded + rand range + shuffle). // time: O(1) per draw; memory: O(1) diff --git a/src/8-misc/simd.cpp b/src/8-misc/simd.cpp index d7600bb..3f65d75 100644 --- a/src/8-misc/simd.cpp +++ b/src/8-misc/simd.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" #include // what: AVX2 usage snippets (i32 add/sum/min/count, f32 dot/add). diff --git a/src/8-misc/sqrt_decomposition_mos_algorithm.cpp b/src/8-misc/sqrt_decomposition_mos_algorithm.cpp index cdfeac5..a97a932 100644 --- a/src/8-misc/sqrt_decomposition_mos_algorithm.cpp +++ b/src/8-misc/sqrt_decomposition_mos_algorithm.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: reorder offline range queries to minimize add/del operations (Mo's algorithm). // time: O((n+q) * sqrt(n)); memory: O(q) @@ -20,7 +20,6 @@ struct mo { q.clear(); } void add_query(int l, int r, int idx) { q.pb({l, r, idx}); } - template void run(Add add, Del del, Out out) { // goal: process queries in Mo order with callbacks. diff --git a/src/8-misc/system_of_difference_constraints.cpp b/src/8-misc/system_of_difference_constraints.cpp index 7820813..6aa7d0a 100644 --- a/src/8-misc/system_of_difference_constraints.cpp +++ b/src/8-misc/system_of_difference_constraints.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: solve difference constraints x_v - x_u <= w with Bellman-Ford. // time: O(nm) via Bellman-Ford; memory: O(n+m) diff --git a/src/8-misc/ternary_search.cpp b/src/8-misc/ternary_search.cpp index 4ebb003..d744f02 100644 --- a/src/8-misc/ternary_search.cpp +++ b/src/8-misc/ternary_search.cpp @@ -1,4 +1,4 @@ -#include "../common/common.hpp" +#include "../0-common/common.hpp" // what: maximize/minimize a unimodal function with ternary search (int/real). // time: int O(log range); real O(it); memory: O(1)