Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/data_structures/deque_op/queue_only.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
//! https://github.com/suisen-cp/cp-library-cpp/blob/main/library/datastructure/deque_aggregation.hpp
//! @code
//! deq dq(a, [](auto x, auto y) {return min(x, y);});
//! deq dq(a, ranges::min);
//! @endcode
//! @time operations are O(1) ammortized
//! @space O(n)
Expand Down
8 changes: 4 additions & 4 deletions library/data_structures/rmq_inc.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once
//! @code
//! rmq_inc rmq3(a, ranges::min);
//! rmq_inc rmq4(a, [&](auto& x, auto& y) {
//! rmq_inc rmq1(a, ranges::min);
//! rmq_inc rmq2(a, [&](auto& x, auto& y) {
//! return min(x, y);
//! });
//! vector<rmq_inc<int, function<int(int, int)>>>
//! rmqs2(3, {{}, NULL});
//! rmqs2[1] = {a, ranges::min};
//! rmqs(3, {{}, NULL});
//! rmqs[1] = {a, ranges::min};
//! @endcode
//! @time O(nlogn + q)
//! @space O(nlogn)
Expand Down
4 changes: 2 additions & 2 deletions library/data_structures/seg_tree.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once
//! https://github.com/kth-competitive-programming/kactl/blob/main/content/data-structures/SegmentTree.h
//! @code
//! tree st0(n, INT_MAX, ranges::min);
//! tree st(n, INT_MAX, [&](int x, int y) -> int {
//! tree st1(n, INT_MAX, ranges::min);
//! tree st2(n, INT_MAX, [&](int x, int y) -> int {
//! return min(x, y);
//! });
//! @endcode
Expand Down
7 changes: 2 additions & 5 deletions library/data_structures/seg_tree_inc.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#pragma once
//! https://codeforces.com/blog/entry/118682
//! @code
//! tree_inc st3(n, int{}, ranges::min);
//! tree_inc st4(n, pii{}, [&](pii x, pii y) -> pii {
//! return min(x, y);
//! });
//! rep(i, 0, n) st3.update(i, a[i]);
//! tree_inc st(n, int{}, ranges::min);
//! rep(i, 0, n) st.update(i, a[i]);
//! @endcode
//! @time O(n + q log n)
//! @space O(n)
Expand Down
4 changes: 2 additions & 2 deletions library/data_structures/seg_tree_uncommon/find_first.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
//! @code
//! seg_tree st1(n);
//! st1.find_first(l, r, [&](ll x, int tl, int tr) ->
//! seg_tree st(n);
//! st.find_first(l, r, [&](ll x, int tl, int tr) ->
//! bool {
//! });
//! @endcode
Expand Down
4 changes: 2 additions & 2 deletions library/data_structures/seg_tree_uncommon/find_last.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
//! @code
//! seg_tree st2(n);
//! st2.find_last(l, r, [&](ll x, int tl, int tr) ->
//! seg_tree st(n);
//! st.find_last(l, r, [&](ll x, int tl, int tr) ->
//! bool {
//! });
//! @endcode
Expand Down
2 changes: 1 addition & 1 deletion library/data_structures/uncommon/disjoint_rmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Disjoint RMQ is like normal RMQ except
//! the 2 query ranges never overlap.
//! @code
//! disjoint_rmq dis_rmq1(a, [&](int x, int y) {
//! disjoint_rmq rmq(a, [&](int x, int y) {
//! return 1LL*x*y%10;
//! });
//! @endcode
Expand Down
2 changes: 1 addition & 1 deletion library/data_structures/uncommon/disjoint_rmq_inc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Disjoint RMQ is like normal RMQ except
//! the 2 query ranges never overlap.
//! @code
//! disjoint_rmq dis_rmq2(a, [&](int x, int y) {
//! disjoint_rmq rmq(a, [&](int x, int y) {
//! return 1LL*x*y%10;
//! });
//! @endcode
Expand Down
10 changes: 5 additions & 5 deletions library/data_structures/uncommon/linear_rmq.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once
//! https://codeforces.com/blog/entry/125371?#comment-1173604
//! @code
//! linear_rmq lr1(a, less());//right-most min
//! linear_rmq lr2(a, less_equal());//left-most min
//! linear_rmq lr3(a, greater());//right-most max
//! linear_rmq lr4(a, greater_equal());//left-most max
//! linear_rmq lr5(a, [&](auto& x, auto& y) {
//! linear_rmq rmq1(a, less());//right-most min
//! linear_rmq rmq2(a, less_equal());//left-most min
//! linear_rmq rmq3(a, greater());//right-most max
//! linear_rmq rmq4(a, greater_equal());//left-most max
//! linear_rmq rmq5(a, [&](auto& x, auto& y) {
//! return x < y;
//! });
//! @endcode
Expand Down
5 changes: 3 additions & 2 deletions library/graphs/bridges_cuts/block_vertex_tree.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once
#include "cuts.hpp"
//! @code
//! cuts cc(adj_c, m);
//! vector<vi> bvt = block_vertex_tree(adj_c, cc);
//! vector<vector<pii>> adj(n);
//! cuts cc(adj, m);
//! vector<vi> bvt = block_vertex_tree(adj, cc);
//! //to loop over each unique bcc containing a node u:
//! for (int bccid : bvt[v]) {
//! bccid -= n;
Expand Down
5 changes: 3 additions & 2 deletions library/graphs/bridges_cuts/bridge_tree.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once
#include "bridges.hpp"
//! @code
//! bridges br(adj_br, m);
//! vector<vi> bt = bridge_tree(adj_br, br);
//! vector<vector<pii>> adj(n);
//! bridges br(adj, m);
//! vector<vi> bt = bridge_tree(adj, br);
//! @endcode
//! @time O(n + m)
//! @space O(n)
Expand Down
9 changes: 4 additions & 5 deletions library/graphs/bridges_cuts/bridges.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#pragma once
//! https://cp-algorithms.com/graph/bridge-searching.html
//! @code
//! vector<vector<pii>> adj_br(n);
//! vector<vector<pii>> adj(n);
//! rep (i, 0, m) {
//! int u, v;
//! cin >> u >> v;
//! u--, v--;
//! adj_br[u].emplace_back(v, i);
//! adj_br[v].emplace_back(u, i);
//! adj[u].emplace_back(v, i);
//! adj[v].emplace_back(u, i);
//! }
//! auto [num_ccs, is_bridge, br_id] =
//! bridges(adj_br, m);
//! auto [num_ccs, is_bridge, br_id] = bridges(adj, m);
//! @endcode
//! is_bridge[edge id] = 1 iff bridge edge
//! br_id[v] = id, 0<=id<num_ccs
Expand Down
8 changes: 4 additions & 4 deletions library/graphs/bridges_cuts/cuts.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#pragma once
//! https://cp-algorithms.com/graph/cutpoints.html
//! @code
//! vector<vector<pii>> adj_c(n);
//! vector<vector<pii>> adj(n);
//! rep (i, 0, m) {
//! int u, v;
//! cin >> u >> v;
//! u--, v--;
//! //self edges not allowed
//! adj_c[u].emplace_back(v, i);
//! adj_c[v].emplace_back(u, i);
//! adj[u].emplace_back(v, i);
//! adj[v].emplace_back(u, i);
//! }
//! auto [num_bccs, is_cut, bcc_id] = cuts(adj_c, m);
//! auto [num_bccs, is_cut, bcc_id] = cuts(adj, m);
//! @endcode
//! is_cut[v] = 1 iff cut node
//! bcc_id[edge id] = id, 0<=id<num_bccs
Expand Down
1 change: 1 addition & 0 deletions library/graphs/complement_graph_ccs.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
//! @code
//! vector<vi> adj(n);
//! auto cc_id = get_complement_graph_ccs(adj);
//! @endcode
//! 0<=cc_id[v]<number of connected components
Expand Down
3 changes: 2 additions & 1 deletion library/graphs/dijkstra.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
//! @code
//! auto d = dijkstra(adj_w, source);
//! vector<vector<pair<int, ll>>> adj(n);
//! auto d = dijkstra(adj, source);
//! @endcode
//! d[v] = min dist from source->..->v
//! @time O(n + (m log m))
Expand Down
1 change: 1 addition & 0 deletions library/graphs/hopcroft_karp.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
//! https://github.com/foreverbell/acm-icpc-cheat-sheet/blob/master/src/graph-algorithm/hopcroft-karp.cpp
//! @code
//! vector<vi> adj(lsz);
//! adj[l].push_back(r); // add edge l <-> r
//! auto [matching_size, to_r, to_l,
//! mvc_l, mvc_r] = hopcroft_karp(adj, rsz);
Expand Down
1 change: 1 addition & 0 deletions library/graphs/strongly_connected_components/scc.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
//! https://github.com/kth-competitive-programming/kactl/blob/main/content/graph/SCC.h
//! @code
//! vector<vi> adj(n);
//! auto [num_sccs, scc_id] = sccs(adj);
//! @endcode
//! scc_id[v] = id, 0<=id<num_sccs
Expand Down
2 changes: 1 addition & 1 deletion library/math/matrix_related/row_reduce.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "../mod_int.hpp"
//! @code
//! auto [rank1, det1] = row_reduce(mat, cols);
//! auto [rank, det] = row_reduce(mat, cols);
//! @endcode
//! columns [0,cols) of mat represent a matrix
//! columns [cols,m) of mat are also
Expand Down
2 changes: 1 addition & 1 deletion library/math/matrix_related/solve_linear_mod.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "row_reduce.hpp"
//! @code
//! auto [rank2, det2, sol] = solve_linear_mod(mat, rhs);
//! auto [rank, det, sol] = solve_linear_mod(mat, rhs);
//! @endcode
//! for each i, 0<=i<n:
//! rhs[i] == sum over j of (mat[i][j]*sol[j])
Expand Down
6 changes: 3 additions & 3 deletions library/math/matrix_related/xor_basis_ordered.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//! https://codeforces.com/blog/entry/68953
//! https://github.com/ssk4988/Hackpack/blob/main/content/numerical/XORBasis.h
//! @code
//! basis_ordered<int> b3;
//! basis_ordered<ll> b4;
//! basis_ordered<bitset<lg>> b5;
//! basis_ordered<int> b1;
//! basis_ordered<ll> b2;
//! basis_ordered<bitset<lg>> b3;
//! @endcode
const int lg = 60;
template<class T> struct basis_ordered {
Expand Down
1 change: 1 addition & 0 deletions library/math/matrix_related/xor_basis_unordered.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! @code
//! basis<int> b1;
//! basis<ll> b2;
//! basis<dynamic_bitset<>> b3;
//! @endcode
//! b.shrink(v) == b.shrink(b.shrink(v))
//! for x in b.b: (bit_floor(x)&b.shrink(v))==0
Expand Down
4 changes: 2 additions & 2 deletions library/monotonic_stack/cartesian_binary_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "monotonic_stack.hpp"
//! @code
//! // right-most min is root
//! auto mono_le3 = mono_st(a, less());
//! auto p1 = cart_binary_tree(mono_le3);
//! auto le = mono_st(a, less());
//! auto p = cart_binary_tree(le);
//!
//! // less_equal() -> left-most min is root
//! // greater() -> right-most max is root
Expand Down
6 changes: 3 additions & 3 deletions library/monotonic_stack/cartesian_k_ary_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
//! p[5] = 9
//!
//! @code
//! auto l = mono_st(a, less()), p =
//! cart_k_ary_tree(a, l); // min cart tree auto l =
//! mono_st(a, greater()), p = cart_k_ary_tree(a, l);
//! auto le = mono_st(a, less()), p =
//! cart_k_ary_tree(a, le); // min cart tree auto le =
//! mono_st(a, greater()), p = cart_k_ary_tree(a, le);
//! // max cart tree bool is_node = (p[i] < i || a[i]
//! != a[p[i]]);
//! @endcode
Expand Down
5 changes: 2 additions & 3 deletions library/monotonic_stack/monotonic_range.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#pragma once
#include "monotonic_stack.hpp"
//! @code
//! auto mono_le2 = mono_st(a, less());
//! auto mono_ri2 = mono_range(mono_le2);
//! vi le = mono_st(a, less()), ri = mono_range(le);
//! // less_equal(), greater(), greater_equal()
//! @endcode
//! when cmp == less():
//! a[mono_le2[i]] < a[i] >= a[mono_ri2[i]]
//! a[le[i]] < a[i] >= a[ri[i]]
//! @time O(n)
//! @space O(n)
vi mono_range(const vi& l) {
Expand Down
4 changes: 2 additions & 2 deletions library/monotonic_stack/monotonic_stack.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once
//! @code
//! auto mono_le1 = mono_st(a, less());
//! vi le = mono_st(a, less());
//! // less_equal(), greater(), greater_equal()
//! @endcode
//! when cmp == less():
//! a[mono_le1[i]] < a[i]
//! a[le[i]] < a[i]
//! @time O(n)
//! @space O(n)
template<class T, class F>
Expand Down
4 changes: 3 additions & 1 deletion library/strings/suffix_array/compare/compare_substrings.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#pragma once
#include "compare_suffixes.hpp"
//! @code
//! int cmp1 = saq.cmp_substrs(l1,r1,l2,r2);
//! auto [sa, sa_inv, lcp] = get_sa(s, 256);
//! sa_query saq(s, sa, sa_inv, lcp);
//! int cmp = saq.cmp_substrs(l1,r1,l2,r2);
//! @endcode
//! requires l1,l2 < n
//! if cmp1<0 then s[l1,r1) < s[l2,r2)
Expand Down
4 changes: 3 additions & 1 deletion library/strings/suffix_array/compare/compare_suffixes.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
//! @code
//! int cmp2 = saq.cmp_sufs(l1,l2);
//! auto [sa, sa_inv, lcp] = get_sa(s, 256);
//! sa_query saq(s, sa, sa_inv, lcp);
//! int cmp = saq.cmp_sufs(l1,l2);
//! @endcode
//! requires l1,l2 < n
//! if cmp2<0 then s[l1,n) < s[l2,n)
Expand Down
2 changes: 2 additions & 0 deletions library/strings/suffix_array/find/find_substring.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once
//! @code
//! auto [sa, sa_inv, lcp] = get_sa(s, 256);
//! sa_query saq(s, sa, sa_inv, lcp);
//! auto [sa_le,sa_ri] = saq.find_substr(s_l,s_r);
//! @endcode
//! requires s_l < n
Expand Down
5 changes: 3 additions & 2 deletions library/strings/suffix_array/suffix_array_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
#include "../../data_structures/rmq.hpp"
#include "find/match.hpp"
//! @code
//! auto [sa1, sa_inv1, lcp1] = get_sa(s, 256);
//! sa_query saq(s, sa1, sa_inv1, lcp1);
//! //or sa_short
//! auto [sa, sa_inv, lcp] = get_sa(s, 256);
//! sa_query saq(s, sa, sa_inv, lcp);
//! @endcode
template<class T> struct sa_query {
int n;
Expand Down
2 changes: 1 addition & 1 deletion library/strings/suffix_array/suffix_array_short.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! https://github.com/atcoder/ac-library/blob/master/atcoder/string.hpp
//! @code
//! // requires s[i]>=0
//! auto [sa2, sa_inv2, lcp2] = sa_short(s);
//! auto [sa, sa_inv, lcp] = sa_short(s);
//! @endcode
//! runs in ~1.5s for 5e5
//! @time O(n * log^2(n))
Expand Down
1 change: 1 addition & 0 deletions library/trees/centroid_decomp.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
//! @code
//! vector<vi> adj(n);
//! centroid(adj, [&](const vector<vi>& adj,
//! int cent, int par_cent) {
//! });
Expand Down
1 change: 1 addition & 0 deletions library/trees/edge_cd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! https://codeforces.com/blog/entry/120446
//! https://youtu.be/wDwaMo5xa-k
//! @code
//! vector<vi> adj(n);
//! edge_cd(adj, [&](const vector<vi>& adj,
//! int cent, int split) {
//! // subtrees of prefix [0, split) of adj[cent]
Expand Down
2 changes: 2 additions & 0 deletions library/trees/extra_members/compress_tree.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "../../monotonic_stack/monotonic_stack.hpp"
//! https://github.com/kth-competitive-programming/kactl/blob/main/content/graph/CompressTree.h
//! @code
//! vector<vi> adj(n);
//! LCA lca(adj);
//! auto [par, orig_node] =
//! lca.compress_tree(subset);
//! @endcode
Expand Down
1 change: 1 addition & 0 deletions library/trees/lca_rmq/lca_rmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../../data_structures/rmq.hpp"
//! https://github.com/kth-competitive-programming/kactl/blob/main/content/graph/LCA.h
//! @code
//! vector<vi> adj(n);
//! LCA lca(adj);
//! @endcode
//! @time O(nlogn + q)
Expand Down
1 change: 1 addition & 0 deletions library/trees/subtree_isomorphism.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
//! @code
//! vector<vi> adj(n);
//! auto [num_distinct_subtrees, iso_id] =
//! subtree_iso(adj);
//! @endcode
Expand Down
Loading
Loading