diff --git a/library/data_structures/deque_op/queue_only.hpp b/library/data_structures/deque_op/queue_only.hpp index 02b086ef..3405eb08 100644 --- a/library/data_structures/deque_op/queue_only.hpp +++ b/library/data_structures/deque_op/queue_only.hpp @@ -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) diff --git a/library/data_structures/rmq_inc.hpp b/library/data_structures/rmq_inc.hpp index 8ee0e001..3b6f7351 100644 --- a/library/data_structures/rmq_inc.hpp +++ b/library/data_structures/rmq_inc.hpp @@ -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>> -//! rmqs2(3, {{}, NULL}); -//! rmqs2[1] = {a, ranges::min}; +//! rmqs(3, {{}, NULL}); +//! rmqs[1] = {a, ranges::min}; //! @endcode //! @time O(nlogn + q) //! @space O(nlogn) diff --git a/library/data_structures/seg_tree.hpp b/library/data_structures/seg_tree.hpp index 4e50f537..6d2d781a 100644 --- a/library/data_structures/seg_tree.hpp +++ b/library/data_structures/seg_tree.hpp @@ -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 diff --git a/library/data_structures/seg_tree_inc.hpp b/library/data_structures/seg_tree_inc.hpp index 022f751b..09b92211 100644 --- a/library/data_structures/seg_tree_inc.hpp +++ b/library/data_structures/seg_tree_inc.hpp @@ -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) diff --git a/library/data_structures/seg_tree_uncommon/find_first.hpp b/library/data_structures/seg_tree_uncommon/find_first.hpp index 15b3266e..84b8abc7 100644 --- a/library/data_structures/seg_tree_uncommon/find_first.hpp +++ b/library/data_structures/seg_tree_uncommon/find_first.hpp @@ -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 diff --git a/library/data_structures/seg_tree_uncommon/find_last.hpp b/library/data_structures/seg_tree_uncommon/find_last.hpp index c344267a..08a015f5 100644 --- a/library/data_structures/seg_tree_uncommon/find_last.hpp +++ b/library/data_structures/seg_tree_uncommon/find_last.hpp @@ -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 diff --git a/library/data_structures/uncommon/disjoint_rmq.hpp b/library/data_structures/uncommon/disjoint_rmq.hpp index ccea631d..d18eb0b4 100644 --- a/library/data_structures/uncommon/disjoint_rmq.hpp +++ b/library/data_structures/uncommon/disjoint_rmq.hpp @@ -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 diff --git a/library/data_structures/uncommon/disjoint_rmq_inc.hpp b/library/data_structures/uncommon/disjoint_rmq_inc.hpp index 9d32ca15..25dd533f 100644 --- a/library/data_structures/uncommon/disjoint_rmq_inc.hpp +++ b/library/data_structures/uncommon/disjoint_rmq_inc.hpp @@ -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 diff --git a/library/data_structures/uncommon/linear_rmq.hpp b/library/data_structures/uncommon/linear_rmq.hpp index e3a6656f..bcf2e028 100644 --- a/library/data_structures/uncommon/linear_rmq.hpp +++ b/library/data_structures/uncommon/linear_rmq.hpp @@ -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 diff --git a/library/graphs/bridges_cuts/block_vertex_tree.hpp b/library/graphs/bridges_cuts/block_vertex_tree.hpp index 7ff403b9..66043a60 100644 --- a/library/graphs/bridges_cuts/block_vertex_tree.hpp +++ b/library/graphs/bridges_cuts/block_vertex_tree.hpp @@ -1,8 +1,9 @@ #pragma once #include "cuts.hpp" //! @code -//! cuts cc(adj_c, m); -//! vector bvt = block_vertex_tree(adj_c, cc); +//! vector> adj(n); +//! cuts cc(adj, m); +//! vector bvt = block_vertex_tree(adj, cc); //! //to loop over each unique bcc containing a node u: //! for (int bccid : bvt[v]) { //! bccid -= n; diff --git a/library/graphs/bridges_cuts/bridge_tree.hpp b/library/graphs/bridges_cuts/bridge_tree.hpp index 9bd5d651..a1c9978f 100644 --- a/library/graphs/bridges_cuts/bridge_tree.hpp +++ b/library/graphs/bridges_cuts/bridge_tree.hpp @@ -1,8 +1,9 @@ #pragma once #include "bridges.hpp" //! @code -//! bridges br(adj_br, m); -//! vector bt = bridge_tree(adj_br, br); +//! vector> adj(n); +//! bridges br(adj, m); +//! vector bt = bridge_tree(adj, br); //! @endcode //! @time O(n + m) //! @space O(n) diff --git a/library/graphs/bridges_cuts/bridges.hpp b/library/graphs/bridges_cuts/bridges.hpp index cff3f8ed..b6b53221 100644 --- a/library/graphs/bridges_cuts/bridges.hpp +++ b/library/graphs/bridges_cuts/bridges.hpp @@ -1,16 +1,15 @@ #pragma once //! https://cp-algorithms.com/graph/bridge-searching.html //! @code -//! vector> adj_br(n); +//! vector> 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> adj_c(n); +//! vector> 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 adj(n); //! auto cc_id = get_complement_graph_ccs(adj); //! @endcode //! 0<=cc_id[v]>> adj(n); +//! auto d = dijkstra(adj, source); //! @endcode //! d[v] = min dist from source->..->v //! @time O(n + (m log m)) diff --git a/library/graphs/hopcroft_karp.hpp b/library/graphs/hopcroft_karp.hpp index 8c26dd9e..919c1982 100644 --- a/library/graphs/hopcroft_karp.hpp +++ b/library/graphs/hopcroft_karp.hpp @@ -1,6 +1,7 @@ #pragma once //! https://github.com/foreverbell/acm-icpc-cheat-sheet/blob/master/src/graph-algorithm/hopcroft-karp.cpp //! @code +//! vector 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); diff --git a/library/graphs/strongly_connected_components/scc.hpp b/library/graphs/strongly_connected_components/scc.hpp index 81bf8777..75baecd3 100644 --- a/library/graphs/strongly_connected_components/scc.hpp +++ b/library/graphs/strongly_connected_components/scc.hpp @@ -1,6 +1,7 @@ #pragma once //! https://github.com/kth-competitive-programming/kactl/blob/main/content/graph/SCC.h //! @code +//! vector adj(n); //! auto [num_sccs, scc_id] = sccs(adj); //! @endcode //! scc_id[v] = id, 0<=id b3; -//! basis_ordered b4; -//! basis_ordered> b5; +//! basis_ordered b1; +//! basis_ordered b2; +//! basis_ordered> b3; //! @endcode const int lg = 60; template struct basis_ordered { diff --git a/library/math/matrix_related/xor_basis_unordered.hpp b/library/math/matrix_related/xor_basis_unordered.hpp index ed8e0e5e..01a114dc 100644 --- a/library/math/matrix_related/xor_basis_unordered.hpp +++ b/library/math/matrix_related/xor_basis_unordered.hpp @@ -4,6 +4,7 @@ //! @code //! basis b1; //! basis b2; +//! basis> b3; //! @endcode //! b.shrink(v) == b.shrink(b.shrink(v)) //! for x in b.b: (bit_floor(x)&b.shrink(v))==0 diff --git a/library/monotonic_stack/cartesian_binary_tree.hpp b/library/monotonic_stack/cartesian_binary_tree.hpp index 0529da86..b9bad14a 100644 --- a/library/monotonic_stack/cartesian_binary_tree.hpp +++ b/library/monotonic_stack/cartesian_binary_tree.hpp @@ -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 diff --git a/library/monotonic_stack/cartesian_k_ary_tree.hpp b/library/monotonic_stack/cartesian_k_ary_tree.hpp index c9049f91..45390b7d 100644 --- a/library/monotonic_stack/cartesian_k_ary_tree.hpp +++ b/library/monotonic_stack/cartesian_k_ary_tree.hpp @@ -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 diff --git a/library/monotonic_stack/monotonic_range.hpp b/library/monotonic_stack/monotonic_range.hpp index c429fcd2..0af8ffb9 100644 --- a/library/monotonic_stack/monotonic_range.hpp +++ b/library/monotonic_stack/monotonic_range.hpp @@ -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) { diff --git a/library/monotonic_stack/monotonic_stack.hpp b/library/monotonic_stack/monotonic_stack.hpp index 27fc648c..cb78968a 100644 --- a/library/monotonic_stack/monotonic_stack.hpp +++ b/library/monotonic_stack/monotonic_stack.hpp @@ -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 diff --git a/library/strings/suffix_array/compare/compare_substrings.hpp b/library/strings/suffix_array/compare/compare_substrings.hpp index bec60361..76f82ffe 100644 --- a/library/strings/suffix_array/compare/compare_substrings.hpp +++ b/library/strings/suffix_array/compare/compare_substrings.hpp @@ -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) diff --git a/library/strings/suffix_array/compare/compare_suffixes.hpp b/library/strings/suffix_array/compare/compare_suffixes.hpp index 7925b191..8fcda411 100644 --- a/library/strings/suffix_array/compare/compare_suffixes.hpp +++ b/library/strings/suffix_array/compare/compare_suffixes.hpp @@ -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) diff --git a/library/strings/suffix_array/find/find_substring.hpp b/library/strings/suffix_array/find/find_substring.hpp index cd5c7b0f..6ae1ca32 100644 --- a/library/strings/suffix_array/find/find_substring.hpp +++ b/library/strings/suffix_array/find/find_substring.hpp @@ -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 diff --git a/library/strings/suffix_array/suffix_array_query.hpp b/library/strings/suffix_array/suffix_array_query.hpp index 1c862e59..4e95130e 100644 --- a/library/strings/suffix_array/suffix_array_query.hpp +++ b/library/strings/suffix_array/suffix_array_query.hpp @@ -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 struct sa_query { int n; diff --git a/library/strings/suffix_array/suffix_array_short.hpp b/library/strings/suffix_array/suffix_array_short.hpp index 67fb29c8..21e631a6 100644 --- a/library/strings/suffix_array/suffix_array_short.hpp +++ b/library/strings/suffix_array/suffix_array_short.hpp @@ -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)) diff --git a/library/trees/centroid_decomp.hpp b/library/trees/centroid_decomp.hpp index b4985478..518ef68c 100644 --- a/library/trees/centroid_decomp.hpp +++ b/library/trees/centroid_decomp.hpp @@ -1,5 +1,6 @@ #pragma once //! @code +//! vector adj(n); //! centroid(adj, [&](const vector& adj, //! int cent, int par_cent) { //! }); diff --git a/library/trees/edge_cd.hpp b/library/trees/edge_cd.hpp index 721a03ec..7f0ffae0 100644 --- a/library/trees/edge_cd.hpp +++ b/library/trees/edge_cd.hpp @@ -3,6 +3,7 @@ //! https://codeforces.com/blog/entry/120446 //! https://youtu.be/wDwaMo5xa-k //! @code +//! vector adj(n); //! edge_cd(adj, [&](const vector& adj, //! int cent, int split) { //! // subtrees of prefix [0, split) of adj[cent] diff --git a/library/trees/extra_members/compress_tree.hpp b/library/trees/extra_members/compress_tree.hpp index 0ab7c3db..182e4c4d 100644 --- a/library/trees/extra_members/compress_tree.hpp +++ b/library/trees/extra_members/compress_tree.hpp @@ -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 adj(n); +//! LCA lca(adj); //! auto [par, orig_node] = //! lca.compress_tree(subset); //! @endcode diff --git a/library/trees/lca_rmq/lca_rmq.hpp b/library/trees/lca_rmq/lca_rmq.hpp index cc45d769..f579ea3b 100644 --- a/library/trees/lca_rmq/lca_rmq.hpp +++ b/library/trees/lca_rmq/lca_rmq.hpp @@ -2,6 +2,7 @@ #include "../../data_structures/rmq.hpp" //! https://github.com/kth-competitive-programming/kactl/blob/main/content/graph/LCA.h //! @code +//! vector adj(n); //! LCA lca(adj); //! @endcode //! @time O(nlogn + q) diff --git a/library/trees/subtree_isomorphism.hpp b/library/trees/subtree_isomorphism.hpp index 5b680219..7a99f00e 100644 --- a/library/trees/subtree_isomorphism.hpp +++ b/library/trees/subtree_isomorphism.hpp @@ -1,5 +1,6 @@ #pragma once //! @code +//! vector adj(n); //! auto [num_distinct_subtrees, iso_id] = //! subtree_iso(adj); //! @endcode diff --git a/tests/scripts/compile_commented_snippets.sh b/tests/scripts/compile_commented_snippets.sh index d1c0db98..fbfea376 100755 --- a/tests/scripts/compile_commented_snippets.sh +++ b/tests/scripts/compile_commented_snippets.sh @@ -11,6 +11,8 @@ git submodule update { echo "#include " echo "using namespace std;" + echo "#include " + echo "using namespace tr2;" cat library_checker_aizu_tests/kactl_macros.hpp echo "const ll mod = (119 << 23) + 1, root = 62;" find ../library/ -type f -name "*.hpp" | grep --invert-match --file=.config/.code_snippet_excluded_file_list | sort | sed 's/^/#include "/; s/$/"/' | cpp -nostdinc -C -P | grep --invert-match --extended-regexp "const int mod = |const ll mod = " @@ -26,12 +28,12 @@ git submodule update echo "vector> mat;" echo "vector> grid;" echo "string s,t;" - echo "int n,m,k,tl,tr,l,r,l1,r1,l2,r2,s_l,s_r,root_l,root_r,source,sink,total_flow,bccid,u,v,rsz,cols,cap;" + echo "int n,m,k,tl,tr,l,r,l1,r1,l2,r2,s_l,s_r,root_l,root_r,source,sink,total_flow,bccid,u,v,lsz,rsz,cols,cap;" } >entire_library_without_main { cat entire_library_without_main - sed --quiet '/\/\/! @code$/,/\/\/! @endcode$/{//!p;}' entire_library_without_main | sed 's/\/\/!//' + sed --quiet '/\/\/! @code$/,/\/\/! @endcode$/p' entire_library_without_main | sed 's/\/\/! @code/{/' | sed 's/\/\/! @endcode/}/' | sed 's/\/\/!//' echo "return 0;" echo "}" } >entire_library.cpp