diff --git a/.github/workflows/programming_team_code_ci.yml b/.github/workflows/programming_team_code_ci.yml index 4b1e67fe..6ac20d8e 100644 --- a/.github/workflows/programming_team_code_ci.yml +++ b/.github/workflows/programming_team_code_ci.yml @@ -27,7 +27,7 @@ jobs: - name: Run tests env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: oj-verify all --tle 35 --timeout 21600 + run: oj-verify all --tle 10 --timeout 21600 check_format_lint: runs-on: ubuntu-latest diff --git a/.verify-helper/timestamps.remote.json b/.verify-helper/timestamps.remote.json index 13df21c7..41c9c00f 100644 --- a/.verify-helper/timestamps.remote.json +++ b/.verify-helper/timestamps.remote.json @@ -6,7 +6,7 @@ "tests/library_checker_aizu_tests/data_structures/binary_trie.test.cpp": "2024-11-17 14:04:03 -0600", "tests/library_checker_aizu_tests/data_structures/bit.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/data_structures/bit_inc.test.cpp": "2024-11-18 09:44:22 -0600", -"tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp": "2024-11-18 09:44:22 -0600", +"tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp": "2024-12-10 11:52:04 -0600", "tests/library_checker_aizu_tests/data_structures/bit_rupq.test.cpp": "2024-12-05 10:41:42 -0600", "tests/library_checker_aizu_tests/data_structures/bit_rurq.test.cpp": "2024-12-05 10:41:42 -0600", "tests/library_checker_aizu_tests/data_structures/bit_walk.test.cpp": "2024-12-14 19:50:29 -0600", @@ -21,7 +21,7 @@ "tests/library_checker_aizu_tests/data_structures/dsu_bipartite.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/data_structures/dsu_restorable.test.cpp": "2024-11-17 14:04:03 -0600", "tests/library_checker_aizu_tests/data_structures/dsu_segtree_undo_trick.test.cpp": "2024-12-14 19:50:29 -0600", -"tests/library_checker_aizu_tests/data_structures/implicit_seg_tree.test.cpp": "2024-11-17 14:04:03 -0600", +"tests/library_checker_aizu_tests/data_structures/implicit_seg_tree.test.cpp": "2024-12-15 09:29:23 -0600", "tests/library_checker_aizu_tests/data_structures/kruskal_tree_aizu.test.cpp": "2024-11-17 14:04:03 -0600", "tests/library_checker_aizu_tests/data_structures/kth_smallest_pst.test.cpp": "2024-12-05 10:41:42 -0600", "tests/library_checker_aizu_tests/data_structures/kth_smallest_wavelet_matrix.test.cpp": "2024-11-19 08:31:51 -0600", @@ -38,40 +38,41 @@ "tests/library_checker_aizu_tests/data_structures/persistent_seg_tree.test.cpp": "2024-12-05 10:41:42 -0600", "tests/library_checker_aizu_tests/data_structures/pq_ds_undo_sliding_window.test.cpp": "2024-12-05 10:41:42 -0600", "tests/library_checker_aizu_tests/data_structures/pq_ds_undo_with_dsu.test.cpp": "2024-12-05 10:41:42 -0600", -"tests/library_checker_aizu_tests/data_structures/range_parallel_dsu.test.cpp": "2024-12-14 19:50:29 -0600", -"tests/library_checker_aizu_tests/data_structures/rmq_all_methods.test.cpp": "2024-12-14 19:50:29 -0600", -"tests/library_checker_aizu_tests/data_structures/rmq_inc.test.cpp": "2024-12-14 15:47:13 -0600", +"tests/library_checker_aizu_tests/data_structures/range_parallel_dsu.test.cpp": "2024-12-15 12:37:34 -0600", +"tests/library_checker_aizu_tests/data_structures/rmq_disjoint_sparse_table.test.cpp": "2024-12-15 09:26:21 -0600", +"tests/library_checker_aizu_tests/data_structures/rmq_linear.test.cpp": "2024-12-15 12:37:34 -0600", +"tests/library_checker_aizu_tests/data_structures/rmq_sparse_table.test.cpp": "2024-12-15 12:37:34 -0600", +"tests/library_checker_aizu_tests/data_structures/rmq_sparse_table_inc.test.cpp": "2024-12-15 09:26:21 -0600", "tests/library_checker_aizu_tests/data_structures/simple_tree.test.cpp": "2024-12-14 15:47:13 -0600", "tests/library_checker_aizu_tests/data_structures/simple_tree_inc.test.cpp": "2024-12-14 15:47:13 -0600", "tests/library_checker_aizu_tests/data_structures/simple_tree_inc_line.test.cpp": "2024-12-14 15:47:13 -0600", "tests/library_checker_aizu_tests/data_structures/simple_tree_line.test.cpp": "2024-12-14 15:47:13 -0600", "tests/library_checker_aizu_tests/flow/dinic_aizu.test.cpp": "2024-11-17 14:04:03 -0600", -"tests/library_checker_aizu_tests/flow/dinic_lib_checker.test.cpp": "2024-11-17 14:04:03 -0600", "tests/library_checker_aizu_tests/flow/hungarian.test.cpp": "2024-11-17 14:04:03 -0600", "tests/library_checker_aizu_tests/flow/min_cost_max_flow.test.cpp": "2024-12-05 10:41:42 -0600", "tests/library_checker_aizu_tests/graphs/biconnected_components.test.cpp": "2024-12-15 09:01:54 -0600", "tests/library_checker_aizu_tests/graphs/connected_components_of_complement_graph.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/graphs/dijkstra_aizu.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/graphs/dijkstra_lib_checker.test.cpp": "2024-12-14 19:50:29 -0600", -"tests/library_checker_aizu_tests/graphs/directed_cycle.test.cpp": "2024-12-15 09:01:54 -0600", +"tests/library_checker_aizu_tests/graphs/directed_cycle.test.cpp": "2024-12-15 12:40:15 -0600", "tests/library_checker_aizu_tests/graphs/enumerate_triangles.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/graphs/hopcroft_karp_aizu.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/graphs/hopcroft_karp_lib_checker.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/graphs/mst.test.cpp": "2024-11-17 14:04:03 -0600", -"tests/library_checker_aizu_tests/graphs/offline_incremental_scc.test.cpp": "2024-12-15 09:01:54 -0600", -"tests/library_checker_aizu_tests/graphs/strongly_connected_components_aizu.test.cpp": "2024-12-15 09:01:54 -0600", -"tests/library_checker_aizu_tests/graphs/strongly_connected_components_lib_checker.test.cpp": "2024-12-15 09:01:54 -0600", +"tests/library_checker_aizu_tests/graphs/offline_incremental_scc.test.cpp": "2024-12-15 12:40:15 -0600", +"tests/library_checker_aizu_tests/graphs/strongly_connected_components_aizu.test.cpp": "2024-12-15 12:40:15 -0600", +"tests/library_checker_aizu_tests/graphs/strongly_connected_components_lib_checker.test.cpp": "2024-12-15 12:40:15 -0600", "tests/library_checker_aizu_tests/graphs/two_edge_components.test.cpp": "2024-12-15 09:01:54 -0600", -"tests/library_checker_aizu_tests/handmade_tests/count_paths_forest.test.cpp": "2024-12-14 19:50:29 -0600", +"tests/library_checker_aizu_tests/handmade_tests/count_paths_forest.test.cpp": "2024-12-15 12:37:34 -0600", "tests/library_checker_aizu_tests/handmade_tests/dsu_size.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/handmade_tests/dynamic_bitset.test.cpp": "2024-11-22 10:47:44 -0600", -"tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp": "2024-12-14 18:43:21 -0600", +"tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp": "2024-12-15 12:37:34 -0600", "tests/library_checker_aizu_tests/handmade_tests/fib_matrix_expo.test.cpp": "2024-12-14 19:50:29 -0600", -"tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp": "2024-12-14 19:50:29 -0600", +"tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp": "2024-12-15 12:37:34 -0600", "tests/library_checker_aizu_tests/handmade_tests/lca_ladder_forest.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/handmade_tests/manacher.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/handmade_tests/merge_st_and_wavelet.test.cpp": "2024-12-14 19:50:29 -0600", -"tests/library_checker_aizu_tests/handmade_tests/mobius.test.cpp": "2024-11-17 14:04:03 -0600", +"tests/library_checker_aizu_tests/handmade_tests/mobius.test.cpp": "2024-12-10 12:31:07 -0600", "tests/library_checker_aizu_tests/handmade_tests/mod_int.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/handmade_tests/n_choose_k.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/handmade_tests/permutation_tree_small.test.cpp": "2024-12-14 15:47:13 -0600", @@ -85,7 +86,7 @@ "tests/library_checker_aizu_tests/loops/supermasks.test.cpp": "2024-11-17 14:04:03 -0600", "tests/library_checker_aizu_tests/math/binary_exponentiation_mod.test.cpp": "2024-11-17 14:04:03 -0600", "tests/library_checker_aizu_tests/math/binary_matrix_mult.test.cpp": "2024-11-17 14:04:03 -0600", -"tests/library_checker_aizu_tests/math/count_paths.test.cpp": "2024-11-17 14:04:03 -0600", +"tests/library_checker_aizu_tests/math/count_paths.test.cpp": "2024-12-15 12:37:34 -0600", "tests/library_checker_aizu_tests/math/derangement.test.cpp": "2024-11-17 14:04:03 -0600", "tests/library_checker_aizu_tests/math/matrix_determinant.test.cpp": "2024-12-14 15:47:13 -0600", "tests/library_checker_aizu_tests/math/matrix_mult.test.cpp": "2024-11-17 14:04:03 -0600", @@ -100,12 +101,12 @@ "tests/library_checker_aizu_tests/math/solve_linear_mod.test.cpp": "2024-12-14 15:47:13 -0600", "tests/library_checker_aizu_tests/math/tetration.test.cpp": "2024-11-17 14:04:03 -0600", "tests/library_checker_aizu_tests/math/totient.test.cpp": "2024-11-17 14:04:03 -0600", -"tests/library_checker_aizu_tests/math/xor_basis.test.cpp": "2024-12-14 15:47:13 -0600", -"tests/library_checker_aizu_tests/math/xor_basis_intersection.test.cpp": "2024-12-14 15:47:13 -0600", +"tests/library_checker_aizu_tests/math/xor_basis.test.cpp": "2024-12-15 13:39:10 -0600", +"tests/library_checker_aizu_tests/math/xor_basis_intersection.test.cpp": "2024-12-15 13:39:10 -0600", "tests/library_checker_aizu_tests/monotonic_stack_related/cartesian_binary_tree.test.cpp": "2024-12-14 19:50:29 -0600", -"tests/library_checker_aizu_tests/monotonic_stack_related/cartesian_k_ary_tree.test.cpp": "2024-12-14 19:50:29 -0600", -"tests/library_checker_aizu_tests/monotonic_stack_related/count_rectangles.test.cpp": "2024-12-14 19:50:29 -0600", -"tests/library_checker_aizu_tests/monotonic_stack_related/max_rect_histogram.test.cpp": "2024-12-14 19:50:29 -0600", +"tests/library_checker_aizu_tests/monotonic_stack_related/cartesian_k_ary_tree.test.cpp": "2024-12-15 12:37:34 -0600", +"tests/library_checker_aizu_tests/monotonic_stack_related/count_rectangles.test.cpp": "2024-12-15 12:37:34 -0600", +"tests/library_checker_aizu_tests/monotonic_stack_related/max_rect_histogram.test.cpp": "2024-12-15 12:37:34 -0600", "tests/library_checker_aizu_tests/strings/kmp.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/strings/lcp_array.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/strings/lcp_query_palindrome.test.cpp": "2024-12-14 19:50:29 -0600", @@ -113,27 +114,25 @@ "tests/library_checker_aizu_tests/strings/lcs_dp.test.cpp": "2024-12-05 10:41:42 -0600", "tests/library_checker_aizu_tests/strings/lcs_queries.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/strings/lcs_queries_merge_sort_tree.test.cpp": "2024-12-05 10:41:42 -0600", -"tests/library_checker_aizu_tests/strings/longest_common_substring.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/strings/manacher.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/strings/multi_matching_bs.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/strings/prefix_function.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/strings/sa_cmp.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/strings/sa_sort_pairs.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/strings/single_matching_bs.test.cpp": "2024-12-14 19:50:29 -0600", -"tests/library_checker_aizu_tests/strings/suffix_array.test.cpp": "2024-12-14 19:50:29 -0600", +"tests/library_checker_aizu_tests/strings/suffix_array.test.cpp": "2024-12-15 12:37:34 -0600", "tests/library_checker_aizu_tests/strings/suffix_array_short.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/strings/trie.test.cpp": "2024-12-05 10:41:42 -0600", "tests/library_checker_aizu_tests/strings/wildcard_pattern_matching.test.cpp": "2024-12-14 19:50:29 -0600", -"tests/library_checker_aizu_tests/trees/cd_jump_on_tree.test.cpp": "2024-12-14 18:43:21 -0600", -"tests/library_checker_aizu_tests/trees/cd_lca.test.cpp": "2024-12-14 18:43:21 -0600", -"tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp": "2024-12-14 19:50:29 -0600", +"tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp": "2024-12-15 12:37:34 -0600", "tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp": "2024-12-14 18:43:21 -0600", "tests/library_checker_aizu_tests/trees/edge_cd_contour_range_update.test.cpp": "2024-12-14 18:43:21 -0600", "tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp": "2024-12-14 18:43:21 -0600", "tests/library_checker_aizu_tests/trees/edge_cd_reroot_dp.test.cpp": "2024-12-14 18:43:21 -0600", -"tests/library_checker_aizu_tests/trees/kth_node_on_path.test.cpp": "2024-12-14 19:50:29 -0600", -"tests/library_checker_aizu_tests/trees/ladder_decomposition.test.cpp": "2024-12-14 19:50:29 -0600", +"tests/library_checker_aizu_tests/trees/kth_path_ladder.test.cpp": "2024-12-15 09:26:21 -0600", +"tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp": "2024-12-15 09:26:21 -0600", +"tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp": "2024-12-15 12:37:34 -0600", "tests/library_checker_aizu_tests/trees/lca_all_methods_aizu.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/trees/lca_all_methods_lib_checker.test.cpp": "2024-12-14 19:50:29 -0600", -"tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp": "2024-12-14 19:50:29 -0600" +"tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp": "2024-12-15 12:37:34 -0600" } \ No newline at end of file diff --git a/library/graphs/strongly_connected_components/add_edges_strongly_connected.hpp b/library/graphs/scc/add_edges_strongly_connected.hpp similarity index 100% rename from library/graphs/strongly_connected_components/add_edges_strongly_connected.hpp rename to library/graphs/scc/add_edges_strongly_connected.hpp diff --git a/library/graphs/strongly_connected_components/offline_incremental_scc.hpp b/library/graphs/scc/offline_incremental_scc.hpp similarity index 80% rename from library/graphs/strongly_connected_components/offline_incremental_scc.hpp rename to library/graphs/scc/offline_incremental_scc.hpp index 2feedbb7..510791bd 100644 --- a/library/graphs/strongly_connected_components/offline_incremental_scc.hpp +++ b/library/graphs/scc/offline_incremental_scc.hpp @@ -13,26 +13,26 @@ vi offline_incremental_scc(vector> eds, int n) { int m = sz(eds); - vi ids(n, -1), joins(m, m), idx(m); + vi ids(n, -1), joins(m, m), idx(m), vs(n), scc_id; iota(all(idx), 0); + vector> adj; auto divide_and_conquer = [&](auto&& self, auto el, auto er, int tl, int tr) { - int mid = tl + (tr - tl) / 2; - vi vs; - vector adj; + adj.clear(); + int mid = midpoint(tl, tr); for (auto it = el; it != er; it++) { auto& [u, v] = eds[*it]; for (int w : {u, v}) { if (ids[w] != -1) continue; - ids[w] = sz(vs); - vs.push_back(w); + ids[w] = sz(adj); + vs[sz(adj)] = w; adj.emplace_back(); } u = ids[u], v = ids[v]; if (*it <= mid) adj[u].push_back(v); } - for (int v : vs) ids[v] = -1; - auto scc_id = sccs(adj).second; + rep(i, 0, sz(adj)) ids[vs[i]] = -1; + scc_id = sccs(adj).second; auto split = partition(el, er, [&](int i) { return scc_id[eds[i][0]] == scc_id[eds[i][1]]; }); @@ -42,10 +42,6 @@ vi offline_incremental_scc(vector> eds, auto& [u, v] = eds[*it]; u = scc_id[u], v = scc_id[v]; } - // deallocate to avoid O(m log m) memory - vi().swap(vs); - vector().swap(adj); - vi().swap(scc_id); self(self, el, split, tl, mid); self(self, split, er, mid, tr); }; diff --git a/library/graphs/strongly_connected_components/scc.hpp b/library/graphs/scc/scc.hpp similarity index 100% rename from library/graphs/strongly_connected_components/scc.hpp rename to library/graphs/scc/scc.hpp diff --git a/library/math/count_paths/count_paths_triangle.hpp b/library/math/count_paths/count_paths_triangle.hpp index bc012b33..a9c59c56 100644 --- a/library/math/count_paths/count_paths_triangle.hpp +++ b/library/math/count_paths/count_paths_triangle.hpp @@ -6,7 +6,8 @@ vl divide_and_conquer(vl h, vl bottom) { { int start = - find_if(all(h), [](ll x) { return x; }) - begin(h); + ranges::find_if(h, [](ll x) { return x; }) - + begin(h); h.erase(begin(h), begin(h) + start); bottom.erase(begin(bottom), begin(bottom) + start); } diff --git a/library/math/matrix_related/xor_basis_unordered.hpp b/library/math/matrix_related/xor_basis_unordered.hpp index 01a114dc..c1c85a4d 100644 --- a/library/math/matrix_related/xor_basis_unordered.hpp +++ b/library/math/matrix_related/xor_basis_unordered.hpp @@ -4,7 +4,6 @@ //! @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 @@ -12,7 +11,7 @@ //! @time O(32) or O(64) //! @space O(32) or O(64) template struct basis { - vector b; + basic_string b; T shrink(T v) { for (T x : b) v = min(v, v ^ x); return v; diff --git a/library/math/matrix_related/xor_basis_unordered_intersection.hpp b/library/math/matrix_related/xor_basis_unordered_intersection.hpp index adf8ee75..e6ac47b9 100644 --- a/library/math/matrix_related/xor_basis_unordered_intersection.hpp +++ b/library/math/matrix_related/xor_basis_unordered_intersection.hpp @@ -6,8 +6,8 @@ template basis intersection(const basis& u, const basis& v) { - vector> w(sz(u.b)); - rep(i, 0, sz(w)) w[i] = {u.b[i], u.b[i]}; + basic_string> w; + for (T e : u.b) w.push_back({e, e}); basis res; for (T e : v.b) { T s = 0; diff --git a/library/math/prime_sieve/mobius.hpp b/library/math/prime_sieve/mobius.hpp index 1e55ff3e..00b8e182 100644 --- a/library/math/prime_sieve/mobius.hpp +++ b/library/math/prime_sieve/mobius.hpp @@ -1,7 +1,7 @@ #pragma once //! @time O(mx log mx) //! @space O(mx) -vi mobius(1'000'005); +vi mobius(100'005); mobius[1] = 1; rep(i, 1, sz(mobius)) for (int j = i + i; j < sz(mobius); j += i) mobius[j] -= mobius[i]; diff --git a/library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp b/library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp index ebe111ce..dc3e4256 100644 --- a/library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp +++ b/library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp @@ -28,8 +28,8 @@ vector count_paths_per_length(const vector& adj) { swap(q, new_q); } } - ranges::sort(child_depths, - [&](auto& x, auto& y) { return sz(x) < sz(y); }); + ranges::sort(child_depths, {}, + [&](auto& x) { return sz(x); }); vector total_depth(1, 1.0); for (auto& cnt_depth : child_depths) { auto prod = conv(total_depth, cnt_depth); diff --git a/library/trees/centroid_decomp_uncommon/lca.hpp b/library/trees/centroid_decomp_uncommon/lca.hpp deleted file mode 100644 index fe37159f..00000000 --- a/library/trees/centroid_decomp_uncommon/lca.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once -#include "../centroid_decomp.hpp" -//! https://codeforces.com/blog/entry/81661#comment-686024 -struct cd_lca { - vi d; - vector mn_d, to_cent; - int cmp(int u, int v) { return d[u] < d[v] ? u : v; } - //! @param adj unrooted, undirected tree - //! @time O(n log n) - //! @space O(n log n) for `mn_d` and `to_cent` vectors - cd_lca(const vector& adj): - d(sz(adj)), mn_d(sz(adj)), to_cent(sz(adj)) { - auto dfs_d = [&](auto&& self, int v, int p) -> void { - for (int u : adj[v]) - if (u != p) d[u] = 1 + d[v], self(self, u, v); - }; - dfs_d(dfs_d, 0, -1); - centroid(adj, - [&](const vector& cd_adj, int cent, int) { - auto dfs = [&](auto&& self, int v, int p) -> void { - mn_d[v].push_back( - p == -1 ? v : cmp(mn_d[p].back(), v)); - to_cent[v].push_back(cent); - for (int u : cd_adj[v]) - if (u != p) self(self, u, v); - }; - dfs(dfs, cent, -1); - }); - } - //! @param u,v nodes - //! @returns lca of u, v; where the root is 0 - //! @time O(log(n)) - //! @space O(1) - int lca(int u, int v) { - for (int i = min(sz(mn_d[u]), sz(mn_d[v])) - 1;; i--) - if (to_cent[u][i] == to_cent[v][i]) - return cmp(mn_d[u][i], mn_d[v][i]); - } -}; diff --git a/tests/.config/.cppcheck_suppression_list b/tests/.config/.cppcheck_suppression_list index e069fe4a..195c11de 100644 --- a/tests/.config/.cppcheck_suppression_list +++ b/tests/.config/.cppcheck_suppression_list @@ -10,7 +10,7 @@ unusedStructMember:../library/trees/ladder_decomposition/linear_kth_par.hpp:17 unusedStructMember:../library/data_structures/dsu/dsu_bipartite.hpp:9 unusedStructMember:../library/trees/linear_lca.hpp:15 unusedScopedObject:../library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp:12 -unusedScopedObject:library_checker_aizu_tests/cd_asserts.hpp:5 +unusedScopedObject:library_checker_aizu_tests/cd_asserts.hpp:6 unusedScopedObject:../library/trees/centroid_decomp_uncommon/count_paths_per_node.hpp:14 unusedScopedObject:library_checker_aizu_tests/trees/centroid_path_dist.test.cpp:29 unusedScopedObject:../library/trees/edge_centroid_decomp_uncommon/count_paths_per_length.hpp:13 @@ -21,9 +21,10 @@ unusedScopedObject:library_checker_aizu_tests/trees/cd_jump_on_tree.test.cpp:58 arrayIndexOutOfBoundsCond:library_checker_aizu_tests/math/linear_prime_sieve.test.cpp:17 negativeContainerIndex:../library/strings/suffix_array/burrows_wheeler.hpp:50 useStlAlgorithm:../kactl/content/numerical/FastFourierTransform.h:53 -useStlAlgorithm:../library/graphs/strongly_connected_components/add_edges_strongly_connected.hpp:58 +useStlAlgorithm:../library/graphs/scc/add_edges_strongly_connected.hpp:58 useStlAlgorithm:../library/math/matrix_related/row_reduce.hpp:28 -useStlAlgorithm:../library/math/count_paths/count_paths_triangle.hpp:23 +useStlAlgorithm:../library/math/count_paths/count_paths_triangle.hpp:24 +useStlAlgorithm:../library/math/matrix_related/xor_basis_unordered_intersection.hpp:10 shadowFunction:../kactl/content/graph/BinaryLifting.h:17 unknownMacro:../kactl/content/graph/BinaryLifting.h:18 constParameter:../kactl/content/graph/BinaryLifting.h:29 diff --git a/tests/library_checker_aizu_tests/cd_asserts.hpp b/tests/library_checker_aizu_tests/cd_asserts.hpp index 440abd69..8dcb6820 100644 --- a/tests/library_checker_aizu_tests/cd_asserts.hpp +++ b/tests/library_checker_aizu_tests/cd_asserts.hpp @@ -2,11 +2,14 @@ #include "../../library/trees/centroid_decomp.hpp" void cd_asserts(const vector>& adj) { vector decomp_size(sz(adj), -1); + vector naive_par_decomp(sz(adj), -1); centroid(adj, [&](const vector>& cd_adj, int cent, int par_cent) -> void { + assert(naive_par_decomp[cent] == par_cent); assert(decomp_size[cent] == -1); auto dfs = [&](auto&& self, int u, int p) -> int { + naive_par_decomp[u] = cent; int sub_size = 1; for (int v : cd_adj[u]) if (v != p) sub_size += self(self, v, u); diff --git a/tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp b/tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp index 7c61c69b..24cbfb29 100644 --- a/tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp +++ b/tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp @@ -19,19 +19,25 @@ int main() { ranges::sort(compress); compress.erase(unique(all(compress)), end(compress)); bit_inc bit(ssize(compress)); + auto get_compressed_idx = [&](int val) -> int { + int l = 0, r = ssize(compress); + while (l + 1 < r) { + int m = (l + r) / 2; + if (compress[m] <= val) l = m; + else r = m; + } + return l; + }; for (int i = 0; i < n; i++) { - int val = ranges::lower_bound(compress, init[i]) - - begin(compress); + int val = get_compressed_idx(init[i]); bit.update(val, 1); } for (auto [type, x] : query) { if (type == 0) { - x = - ranges::lower_bound(compress, x) - begin(compress); + x = get_compressed_idx(x); if (bit.query(x, x) == 0) bit.update(x, 1); } else if (type == 1) { - x = - ranges::lower_bound(compress, x) - begin(compress); + x = get_compressed_idx(x); if (bit.query(x, x) == 1) bit.update(x, -1); } else if (type == 2) { int res = bit.walk(x); @@ -39,18 +45,15 @@ int main() { cout << -1 << '\n'; else cout << compress[res] << '\n'; } else if (type == 3) { - x = - ranges::lower_bound(compress, x) - begin(compress); + x = get_compressed_idx(x); cout << bit.query(x) << '\n'; } else if (type == 4) { - x = - ranges::lower_bound(compress, x) - begin(compress); + x = get_compressed_idx(x); int res = bit.prev(x); if (res == -1) cout << -1 << '\n'; else cout << compress[res] << '\n'; } else { - x = - ranges::lower_bound(compress, x) - begin(compress); + x = get_compressed_idx(x); int res = bit.next(x); if (res == ssize(bit.s)) cout << -1 << '\n'; else cout << compress[res] << '\n'; diff --git a/tests/library_checker_aizu_tests/data_structures/range_parallel_dsu.test.cpp b/tests/library_checker_aizu_tests/data_structures/range_parallel_dsu.test.cpp index 3dd445ad..d9e05292 100644 --- a/tests/library_checker_aizu_tests/data_structures/range_parallel_dsu.test.cpp +++ b/tests/library_checker_aizu_tests/data_structures/range_parallel_dsu.test.cpp @@ -1,8 +1,8 @@ #define PROBLEM \ "https://judge.yosupo.jp/problem/range_parallel_unionfind" +#undef _GLIBCXX_DEBUG #include "../template.hpp" #include "../../../library/data_structures/dsu/range_parallel_dsu.hpp" -#include "../../../library/contest/random.hpp" #include "../../../library/data_structures/dsu/range_parallel_equivalence_classes.hpp" #include "../../../library/math/mod_int.hpp" int main() { @@ -23,14 +23,15 @@ int main() { x[u] = x[u] + x[v]; }; vector> queries; + queries.reserve(q); for (int qq = 0; qq < q; qq++) { int k, a, b; cin >> k >> a >> b; dsu.join(a, b, k, f); queries.push_back({a, b, k}); cout << ans.x << '\n'; - if (qq <= 10 || abs(q - qq) <= 10 || - rnd(0, 50'000) == 0) { + if (qq == 0 || qq == 1 || qq == 10 || qq == 1000 || + qq == 100'000 || qq == q - 1) { auto uf = get_rp_dsu(queries, n); vector sums(n); mint offline_ans = 0; diff --git a/tests/library_checker_aizu_tests/data_structures/rmq_all_methods.test.cpp b/tests/library_checker_aizu_tests/data_structures/rmq_all_methods.test.cpp deleted file mode 100644 index fa84e77d..00000000 --- a/tests/library_checker_aizu_tests/data_structures/rmq_all_methods.test.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#define PROBLEM "https://judge.yosupo.jp/problem/staticrmq" -#include "../template.hpp" -#include "../mono_st_asserts.hpp" -#include "../../../library/data_structures/rmq.hpp" -#include "../../../library/data_structures/uncommon/disjoint_rmq.hpp" -#include "../../../library/data_structures/uncommon/linear_rmq.hpp" -int mn(int x, int y) { return min(x, y); } -bool my_cmp(int x, int y) { return x < y; } -int main() { - cin.tie(0)->sync_with_stdio(0); - { - RMQ rmq_without_template(vector(), mn); - disjoint_rmq disjoint_rmq_without_template( - vector(), mn); - linear_rmq lin_rmq_without_template(vector(), - my_cmp); - } - int n, q; - cin >> n >> q; - vector a(n); - for (int i = 0; i < n; i++) cin >> a[i]; - mono_st_asserts(a); - RMQ rmq(a, [](auto x, auto y) { return min(x, y); }); - disjoint_rmq dis_rmq(a, - [](auto x, auto y) { return min(x, y); }); - linear_rmq lin_rmq(a, less()); - while (q--) { - int l, r; - cin >> l >> r; - int idx_min = lin_rmq.query_idx(l, r - 1); - assert(l <= idx_min && idx_min < r); - assert(lin_rmq.query(l, r - 1) == a[idx_min]); - assert(a[idx_min] == rmq.query(l, r)); - assert(a[idx_min] == dis_rmq.query(l, r)); - cout << a[idx_min] << '\n'; - } -} diff --git a/tests/library_checker_aizu_tests/data_structures/rmq_disjoint_sparse_table.test.cpp b/tests/library_checker_aizu_tests/data_structures/rmq_disjoint_sparse_table.test.cpp new file mode 100644 index 00000000..10924cc2 --- /dev/null +++ b/tests/library_checker_aizu_tests/data_structures/rmq_disjoint_sparse_table.test.cpp @@ -0,0 +1,16 @@ +#define PROBLEM "https://judge.yosupo.jp/problem/staticrmq" +#include "../template.hpp" +#include "../../../library/data_structures/uncommon/disjoint_rmq.hpp" +int main() { + cin.tie(0)->sync_with_stdio(0); + int n, q; + cin >> n >> q; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + disjoint_rmq dis_rmq(a, ranges::min); + while (q--) { + int l, r; + cin >> l >> r; + cout << dis_rmq.query(l, r) << '\n'; + } +} diff --git a/tests/library_checker_aizu_tests/data_structures/rmq_linear.test.cpp b/tests/library_checker_aizu_tests/data_structures/rmq_linear.test.cpp new file mode 100644 index 00000000..90a06dcf --- /dev/null +++ b/tests/library_checker_aizu_tests/data_structures/rmq_linear.test.cpp @@ -0,0 +1,38 @@ +#define PROBLEM "https://judge.yosupo.jp/problem/staticrmq" +#include "../template.hpp" +#include "../../../library/data_structures/uncommon/linear_rmq.hpp" +int main() { + cin.tie(0)->sync_with_stdio(0); + int n, q; + cin >> n >> q; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + linear_rmq rmq_less(a, less()); + linear_rmq rmq_less_equal(a, less_equal()); + vector neg_a(n); + for (int i = 0; i < n; i++) neg_a[i] = -a[i]; + linear_rmq rmq_greater(neg_a, greater()); + linear_rmq rmq_greater_equal(neg_a, greater_equal()); + while (q--) { + int l, r; + cin >> l >> r; + int idx_right_min = rmq_less.query_idx(l, r - 1); + assert(idx_right_min + 1 == r || + rmq_less.query(idx_right_min + 1, r - 1) > + a[idx_right_min]); + assert(l <= idx_right_min && idx_right_min < r); + assert(rmq_less.query(l, r - 1) == a[idx_right_min]); + assert( + idx_right_min == rmq_greater.query_idx(l, r - 1)); + int idx_left_min = rmq_less_equal.query_idx(l, r - 1); + assert(l == idx_left_min || + rmq_less_equal.query(l, idx_left_min - 1) > + a[idx_left_min]); + assert(l <= idx_left_min && idx_left_min < r); + assert(idx_left_min == + rmq_greater_equal.query_idx(l, r - 1)); + assert(a[idx_right_min] == a[idx_left_min]); + assert(idx_left_min <= idx_right_min); + cout << a[idx_right_min] << '\n'; + } +} diff --git a/tests/library_checker_aizu_tests/data_structures/rmq_sparse_table.test.cpp b/tests/library_checker_aizu_tests/data_structures/rmq_sparse_table.test.cpp new file mode 100644 index 00000000..60f27454 --- /dev/null +++ b/tests/library_checker_aizu_tests/data_structures/rmq_sparse_table.test.cpp @@ -0,0 +1,19 @@ +#define PROBLEM "https://judge.yosupo.jp/problem/staticrmq" +#include "../template.hpp" +#include "../mono_st_asserts.hpp" +#include "../../../library/data_structures/rmq.hpp" +int mn(int x, int y) { return min(x, y); } +int main() { + cin.tie(0)->sync_with_stdio(0); + int n, q; + cin >> n >> q; + vector a(n); + for (int i = 0; i < n; i++) cin >> a[i]; + mono_st_asserts(a); + RMQ rmq(a, ranges::min); + while (q--) { + int l, r; + cin >> l >> r; + cout << rmq.query(l, r) << '\n'; + } +} diff --git a/tests/library_checker_aizu_tests/data_structures/rmq_inc.test.cpp b/tests/library_checker_aizu_tests/data_structures/rmq_sparse_table_inc.test.cpp similarity index 84% rename from tests/library_checker_aizu_tests/data_structures/rmq_inc.test.cpp rename to tests/library_checker_aizu_tests/data_structures/rmq_sparse_table_inc.test.cpp index 2d1f8f29..aca314c6 100644 --- a/tests/library_checker_aizu_tests/data_structures/rmq_inc.test.cpp +++ b/tests/library_checker_aizu_tests/data_structures/rmq_sparse_table_inc.test.cpp @@ -7,8 +7,7 @@ int main() { cin >> n >> q; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; - rmq_inc rmq(a, - [&](auto& x, auto& y) { return min(x, y); }); + rmq_inc rmq(a, ranges::min); while (q--) { int l, r; cin >> l >> r; diff --git a/tests/library_checker_aizu_tests/flow/dinic_lib_checker.test.cpp b/tests/library_checker_aizu_tests/flow/dinic_lib_checker.test.cpp deleted file mode 100644 index 875d720d..00000000 --- a/tests/library_checker_aizu_tests/flow/dinic_lib_checker.test.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#define PROBLEM \ - "https://judge.yosupo.jp/problem/bipartitematching" -#include "../template.hpp" -#include "../../../library/flow/dinic.hpp" -#include "../dinic_asserts.hpp" -int main() { - cin.tie(0)->sync_with_stdio(0); - int l, r, m; - cin >> l >> r >> m; - const int source = l + r; - const int sink = l + r + 1; - dinic d(l + r + 2); - for (int i = 0; i < l; i++) d.add_edge(source, i, 1); - for (int i = 0; i < r; i++) d.add_edge(i + l, sink, 1); - vector edge_ids(m); - for (int i = 0; i < m; i++) { - int u, v; - cin >> u >> v; - edge_ids[i] = d.add_edge(u, v + l, 1); - } - ll total_flow = d.calc(source, sink); - cout << total_flow << '\n'; - dinic_asserts(d, source, sink, total_flow); - for (int i = 0; i < m; i++) { - dinic::edge an_edge = d.edges[edge_ids[i]]; - if (an_edge.flow() == 1) - cout << an_edge.v << ' ' << an_edge.to - l << '\n'; - } - return 0; -} diff --git a/tests/library_checker_aizu_tests/graphs/offline_incremental_scc.test.cpp b/tests/library_checker_aizu_tests/graphs/offline_incremental_scc.test.cpp index fb38b033..603c7edd 100644 --- a/tests/library_checker_aizu_tests/graphs/offline_incremental_scc.test.cpp +++ b/tests/library_checker_aizu_tests/graphs/offline_incremental_scc.test.cpp @@ -2,9 +2,7 @@ "https://judge.yosupo.jp/problem/incremental_scc" #include "../template.hpp" #include "../../../kactl/content/data-structures/UnionFind.h" -#include "../../../library/contest/random.hpp" -#include "../../../library/graphs/strongly_connected_components/offline_incremental_scc.hpp" -#include "../../../library/graphs/strongly_connected_components/scc.hpp" +#include "../../../library/graphs/scc/offline_incremental_scc.hpp" #include "../../../library/math/mod_int.hpp" int main() { cin.tie(0)->sync_with_stdio(0); @@ -17,11 +15,11 @@ int main() { auto joins = offline_incremental_scc(eds, n); // assert joins[i] == -1 for self-edges for (int t = 0; t < m; t++) - if (eds[t][0] == eds[t][1]) assert(joins[t] == -1); + assert((eds[t][0] == eds[t][1]) == (joins[t] == -1)); vector order(m); iota(all(order), 0); - sort(all(order), - [&](int i, int j) { return joins[i] < joins[j]; }); + ranges::sort(all(order), {}, + [&](int i) { return joins[i]; }); UF uf(n); mint sum = 0; for (int t = 0, it = 0; t < m; t++) { diff --git a/tests/library_checker_aizu_tests/graphs/strongly_connected_components_aizu.test.cpp b/tests/library_checker_aizu_tests/graphs/strongly_connected_components_aizu.test.cpp index 5c397092..e9e42a8d 100644 --- a/tests/library_checker_aizu_tests/graphs/strongly_connected_components_aizu.test.cpp +++ b/tests/library_checker_aizu_tests/graphs/strongly_connected_components_aizu.test.cpp @@ -2,7 +2,7 @@ "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_C" #include "../template.hpp" #include "../scc_asserts.hpp" -#include "../../../library/graphs/strongly_connected_components/add_edges_strongly_connected.hpp" +#include "../../../library/graphs/scc/add_edges_strongly_connected.hpp" int main() { cin.tie(0)->sync_with_stdio(0); int n, m; diff --git a/tests/library_checker_aizu_tests/graphs/strongly_connected_components_lib_checker.test.cpp b/tests/library_checker_aizu_tests/graphs/strongly_connected_components_lib_checker.test.cpp index 82d6e0c2..08d7e4fa 100644 --- a/tests/library_checker_aizu_tests/graphs/strongly_connected_components_lib_checker.test.cpp +++ b/tests/library_checker_aizu_tests/graphs/strongly_connected_components_lib_checker.test.cpp @@ -1,7 +1,7 @@ #define PROBLEM "https://judge.yosupo.jp/problem/scc" #include "../template.hpp" #include "../scc_asserts.hpp" -#include "../../../library/graphs/strongly_connected_components/add_edges_strongly_connected.hpp" +#include "../../../library/graphs/scc/add_edges_strongly_connected.hpp" int main() { cin.tie(0)->sync_with_stdio(0); int n, m; diff --git a/tests/library_checker_aizu_tests/handmade_tests/count_paths_forest.test.cpp b/tests/library_checker_aizu_tests/handmade_tests/count_paths_forest.test.cpp index 7a047167..b099d875 100644 --- a/tests/library_checker_aizu_tests/handmade_tests/count_paths_forest.test.cpp +++ b/tests/library_checker_aizu_tests/handmade_tests/count_paths_forest.test.cpp @@ -6,6 +6,7 @@ #include "../../../library/data_structures/dsu/dsu_restorable.hpp" #include "../../../library/trees/tree_lift/tree_lift.hpp" #include "../../../library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp" +#include "../cd_asserts.hpp" vector> naive(const vector>& adj, dsu_restorable& dsu) { tree_lift tl(adj); @@ -37,6 +38,7 @@ int main() { adj[v].push_back(u); } } + cd_asserts(adj); vector> cnts_naive = naive(adj, dsu); for (int k = 1; k <= n; k++) assert( diff --git a/tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp b/tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp index 81f1cfb8..df92f5e3 100644 --- a/tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp +++ b/tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp @@ -20,7 +20,7 @@ int main() { assert(false); }); } - for (int n = 2; n <= 8; n++) { + for (int n = 2; n <= 7; n++) { int num_codes = mpow(n, n - 2).x; vector> pruf_codes(num_codes, vector(n - 2)); diff --git a/tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp b/tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp index b1b661b5..8bb0531a 100644 --- a/tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp +++ b/tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp @@ -121,8 +121,8 @@ struct functional_graph_processor { }; int main() { cin.tie(0)->sync_with_stdio(0); - for (int num_tests = 1000; num_tests--;) { - int n = rnd(1, 10000); + for (int num_tests = 100; num_tests--;) { + int n = rnd(1, 1000); vector a(n); for (int i = 0; i < n; i++) a[i] = rnd(0, n - 1); auto [t, cycle] = func_graph(a); diff --git a/tests/library_checker_aizu_tests/handmade_tests/mobius.test.cpp b/tests/library_checker_aizu_tests/handmade_tests/mobius.test.cpp index dffcef79..0132e131 100644 --- a/tests/library_checker_aizu_tests/handmade_tests/mobius.test.cpp +++ b/tests/library_checker_aizu_tests/handmade_tests/mobius.test.cpp @@ -5,7 +5,6 @@ int main() { cin.tie(0)->sync_with_stdio(0); #include "../../../library/math/prime_sieve/mobius.hpp" -#include "../../../library/math/prime_sieve/calc_sieve.hpp" #include "../../../library/math/prime_sieve/is_prime.hpp" assert(is_prime(2)); for (int i = 1; i < sz(mobius); i++) { diff --git a/tests/library_checker_aizu_tests/mono_st_asserts.hpp b/tests/library_checker_aizu_tests/mono_st_asserts.hpp index fe8c18b7..06ee62a6 100644 --- a/tests/library_checker_aizu_tests/mono_st_asserts.hpp +++ b/tests/library_checker_aizu_tests/mono_st_asserts.hpp @@ -2,7 +2,6 @@ #include "../../library/monotonic_stack/monotonic_range.hpp" #include "../../library/monotonic_stack/cartesian_binary_tree.hpp" #include "../../library/monotonic_stack/cartesian_k_ary_tree.hpp" -#include "../../library/data_structures/rmq.hpp" #include "../../library/data_structures/uncommon/linear_rmq.hpp" tuple>, vector> min_cartesian_tree(const vector& a, @@ -38,36 +37,8 @@ void mono_st_asserts(const vector& a) { compares.push_back(greater_equal()); int n = sz(a); for (auto cmp : compares) { - vector init(n); - iota(begin(init), end(init), 0); - RMQ rmq(init, [&](int x, int y) -> int { - return cmp(a[x], a[y]) ? x : y; - }); - linear_rmq lin_rmq(a, cmp); auto l = mono_st(a, cmp), r = mono_range(l), p = cart_binary_tree(l); - { - int iterations = 0; - queue> q; - q.push({0, n, -1}); // node_le, node_ri, parent - while (!empty(q)) { - auto [node_le, node_ri, node_par] = q.front(); - q.pop(); - if (node_le == node_ri) continue; - iterations++; - int idx_root = rmq.query(node_le, node_ri); - int idx_root_2 = - lin_rmq.query_idx(node_le, node_ri - 1); - assert(idx_root == idx_root_2); - assert(node_le <= idx_root && idx_root < node_ri); - assert(l[idx_root] == node_le - 1); - assert(r[idx_root] == node_ri); - assert(p[idx_root] == node_par); - q.push({node_le, idx_root, idx_root}); - q.push({idx_root + 1, node_ri, idx_root}); - } - assert(iterations == n); - } { vector old_way_ri = mono_st(vi{rbegin(a), rend(a)}, [&](int x, int y) { return !cmp(y, x); }); @@ -89,8 +60,6 @@ void mono_st_asserts(const vector& a) { assert(cmp(a[i], a[j])); assert(cmp(a[i], a[r[j] - 1])); assert(cmp(a[i], a[j + (r[j] - j) / 2])); - int range_op = a[rmq.query(j, r[j])]; - assert(cmp(a[i], range_op)); iterations++; } } diff --git a/tests/library_checker_aizu_tests/scc_asserts.hpp b/tests/library_checker_aizu_tests/scc_asserts.hpp index 48edbaae..b436c02a 100644 --- a/tests/library_checker_aizu_tests/scc_asserts.hpp +++ b/tests/library_checker_aizu_tests/scc_asserts.hpp @@ -1,7 +1,7 @@ #pragma once #include "../../library/contest/random.hpp" -#include "../../library/graphs/strongly_connected_components/add_edges_strongly_connected.hpp" -#include "../../library/graphs/strongly_connected_components/offline_incremental_scc.hpp" +#include "../../library/graphs/scc/add_edges_strongly_connected.hpp" +#include "../../library/graphs/scc/offline_incremental_scc.hpp" void scc_asserts(const vector>& adj) { int n = sz(adj); auto [num_sccs, scc_id] = sccs(adj); diff --git a/tests/library_checker_aizu_tests/strings/longest_common_substring.test.cpp b/tests/library_checker_aizu_tests/strings/longest_common_substring.test.cpp index 79cd3a4a..0902301d 100644 --- a/tests/library_checker_aizu_tests/strings/longest_common_substring.test.cpp +++ b/tests/library_checker_aizu_tests/strings/longest_common_substring.test.cpp @@ -1,26 +1,23 @@ #define PROBLEM \ "https://judge.yosupo.jp/problem/longest_common_substring" #include "../template.hpp" -#include "../../../library/strings/suffix_array/suffix_array_query.hpp" +#include "../../../library/strings/suffix_array/suffix_array.hpp" int main() { cin.tie(0)->sync_with_stdio(0); string s, t; cin >> s >> t; string both = s + '$' + t; auto [sa, sa_inv, lcp] = get_sa(both, 256); - sa_query sf_a(both, sa, sa_inv, lcp); pair substr_s = {0, 0}, substr_t = {0, 0}; - for (int i = 0; i < sz(sf_a.lcp); i++) { - if (both[sf_a.sa[i]] == '$' || - both[sf_a.sa[i + 1]] == '$') + for (int i = 0; i < sz(lcp); i++) { + if (both[sa[i]] == '$' || both[sa[i + 1]] == '$') continue; - bool before_in_s = (sf_a.sa[i] < sz(s)); - bool after_in_s = (sf_a.sa[i + 1] < sz(s)); + bool before_in_s = (sa[i] < sz(s)); + bool after_in_s = (sa[i + 1] < sz(s)); if (before_in_s ^ after_in_s) { - if (sf_a.lcp[i] > substr_s.second - substr_s.first) { - substr_s = {sf_a.sa[i], sf_a.sa[i] + sf_a.lcp[i]}; - substr_t = { - sf_a.sa[i + 1], sf_a.sa[i + 1] + sf_a.lcp[i]}; + if (lcp[i] > substr_s.second - substr_s.first) { + substr_s = {sa[i], sa[i] + lcp[i]}; + substr_t = {sa[i + 1], sa[i + 1] + lcp[i]}; if (after_in_s) swap(substr_s, substr_t); substr_t.first -= int(sz(s)) + 1; substr_t.second -= int(sz(s)) + 1; diff --git a/tests/library_checker_aizu_tests/trees/cd_jump_on_tree.test.cpp b/tests/library_checker_aizu_tests/trees/cd_jump_on_tree.test.cpp deleted file mode 100644 index 8638c6d9..00000000 --- a/tests/library_checker_aizu_tests/trees/cd_jump_on_tree.test.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#define PROBLEM \ - "https://judge.yosupo.jp/problem/jump_on_tree" -#include "../template.hpp" -#include "../cd_asserts.hpp" -#include "../../../library/trees/centroid_decomp.hpp" -int main() { - cin.tie(0)->sync_with_stdio(0); - int n, q; - cin >> n >> q; - vector> adj(n); - for (int i = 0; i < n - 1; i++) { - int u, v; - cin >> u >> v; - adj[u].push_back(v); - adj[v].push_back(u); - } - cd_asserts(adj); - vector cent_par(n), cent_depth(n); - vector> c_depth(n); - centroid(adj, - [&](const vector& cent_adj, int cent, - int par_cent) { - cent_par[cent] = par_cent; - if (par_cent != -1) - cent_depth[cent] = 1 + cent_depth[par_cent]; - auto dfs = [&](auto&& self, int v, int p, - int d) -> void { - c_depth[v].push_back(d); - for (int ch : cent_adj[v]) { - if (ch == p) continue; - self(self, ch, v, d + 1); - } - }; - dfs(dfs, cent, -1, 0); - }); - vector>> queries(n); - vector res(q); - for (int q_idx = 0; q_idx < q; q_idx++) { - int s, t, i; - cin >> s >> t >> i; - int u = s, v = t; - while (u != v) - if (cent_depth[u] > cent_depth[v]) u = cent_par[u]; - else v = cent_par[v]; - int lca_d = cent_depth[u]; - if (i > c_depth[s][lca_d] + c_depth[t][lca_d]) - res[q_idx] = -1; - else if (i < c_depth[s][lca_d]) { - queries[s].push_back({lca_d, i, q_idx}); - } else { - queries[t].push_back({lca_d, - c_depth[s][lca_d] + c_depth[t][lca_d] - i, q_idx}); - } - } - for (int i = 0; i < n; i++) - sort(begin(queries[i]), end(queries[i])); - vector pos(n); - centroid(adj, - [&](const vector& cent_adj, int cent, int) { - vector st; - auto dfs = [&](auto&& self, int v, int p) -> void { - st.push_back(v); - while (pos[v] < sz(queries[v]) && - queries[v][pos[v]][0] == cent_depth[cent]) { - auto [_, k, q_idx] = queries[v][pos[v]]; - res[q_idx] = st[sz(st) - 1 - k]; - pos[v]++; - } - for (int ch : cent_adj[v]) { - if (ch == p) continue; - self(self, ch, v); - } - st.pop_back(); - }; - dfs(dfs, cent, -1); - }); - for (int i = 0; i < q; i++) cout << res[i] << '\n'; -} diff --git a/tests/library_checker_aizu_tests/trees/cd_lca.test.cpp b/tests/library_checker_aizu_tests/trees/cd_lca.test.cpp deleted file mode 100644 index e5a2f72a..00000000 --- a/tests/library_checker_aizu_tests/trees/cd_lca.test.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#define PROBLEM "https://judge.yosupo.jp/problem/lca" -// without this, the test runs in like 34 seconds -#undef _GLIBCXX_DEBUG -#include "../template.hpp" -#include "../cd_asserts.hpp" -#include "../../../library/trees/centroid_decomp_uncommon/lca.hpp" -int main() { - cin.tie(0)->sync_with_stdio(0); - int n, q; - cin >> n >> q; - vector> adj(n); - for (int i = 1; i < n; i++) { - int par; - cin >> par; - adj[par].push_back(i); - adj[i].push_back(par); - } - cd_asserts(adj); - cd_lca lca(adj); - for (int i = 0; i < n; i++) assert(lca.lca(i, i) == i); - while (q--) { - int u, v; - cin >> u >> v; - cout << lca.lca(u, v) << '\n'; - } -} diff --git a/tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp b/tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp index a7aad051..d1e32efb 100644 --- a/tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp +++ b/tests/library_checker_aizu_tests/trees/count_paths_per_length.test.cpp @@ -1,9 +1,6 @@ #define PROBLEM \ "https://judge.yosupo.jp/problem/frequency_table_of_tree_distance" #include "../template.hpp" -#include "../cd_asserts.hpp" -#include "../../../library/contest/random.hpp" -#include "../../../library/trees/centroid_decomp_uncommon/count_paths_per_node.hpp" #include "../../../library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp" int main() { cin.tie(0)->sync_with_stdio(0); @@ -16,16 +13,7 @@ int main() { adj[u].push_back(v); adj[v].push_back(u); } - cd_asserts(adj); vector cnt_len = count_paths_per_length(adj); - if (n >= 2) { - int k = rnd(1, n - 1); - vector count_paths = count_paths_per_node(adj, k); - ll sum = accumulate(begin(count_paths), - end(count_paths), 0LL); - assert(sum % (k + 1) == 0); - assert(sum / (k + 1) == cnt_len[k]); - } for (int i = 1; i < n; i++) cout << cnt_len[i] << " "; cout << '\n'; return 0; diff --git a/tests/library_checker_aizu_tests/trees/ladder_decomposition.test.cpp b/tests/library_checker_aizu_tests/trees/kth_path_ladder.test.cpp similarity index 100% rename from tests/library_checker_aizu_tests/trees/ladder_decomposition.test.cpp rename to tests/library_checker_aizu_tests/trees/kth_path_ladder.test.cpp diff --git a/tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp b/tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp new file mode 100644 index 00000000..40055b99 --- /dev/null +++ b/tests/library_checker_aizu_tests/trees/kth_path_linear.test.cpp @@ -0,0 +1,26 @@ +#define PROBLEM \ + "https://judge.yosupo.jp/problem/jump_on_tree" +#include "../template.hpp" +#include "../../../library/trees/linear_kth_path.hpp" +#include "../../../library/trees/lca_rmq/lca_rmq.hpp" +#include "../compress_tree_asserts.hpp" +int main() { + cin.tie(0)->sync_with_stdio(0); + int n, q; + cin >> n >> q; + vector> adj(n); + for (int i = 0; i < n - 1; i++) { + int u, v; + cin >> u >> v; + adj[u].push_back(v); + adj[v].push_back(u); + } + linear_kth_path lin_kth_path(adj); + LCA lc(adj); + compress_tree_asserts(adj, lc); + while (q--) { + int u, v, k; + cin >> u >> v >> k; + cout << lin_kth_path.kth_path(u, v, k) << '\n'; + } +} diff --git a/tests/library_checker_aizu_tests/trees/kth_node_on_path.test.cpp b/tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp similarity index 50% rename from tests/library_checker_aizu_tests/trees/kth_node_on_path.test.cpp rename to tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp index b8f01445..376782a2 100644 --- a/tests/library_checker_aizu_tests/trees/kth_node_on_path.test.cpp +++ b/tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp @@ -4,14 +4,11 @@ #include "../../../library/contest/random.hpp" #include "../../../library/trees/tree_lift/tree_lift.hpp" #include "../../../library/trees/lca_rmq/lca_rmq.hpp" -#include "../../../library/trees/linear_lca.hpp" -#include "../../../library/trees/linear_kth_path.hpp" -#include "../compress_tree_asserts.hpp" int main() { cin.tie(0)->sync_with_stdio(0); int n, q; cin >> n >> q; - vector adj(n); + vector> adj(n); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; @@ -20,18 +17,12 @@ int main() { } tree_lift tl(adj); LCA lc(adj); - linear_kth_path lin_kth_path(adj); - compress_tree_asserts(adj, lc); while (q--) { int u, v, k; cin >> u >> v >> k; int dist_in_edges = tl.dist_edges(u, v); assert(dist_in_edges == lc.dist_edges(u, v)); - assert(dist_in_edges == - lin_kth_path.lin_lca.dist_edges(u, v)); - int res = tl.kth_path(u, v, k); - assert(res == lin_kth_path.kth_path(u, v, k)); - cout << res << '\n'; + cout << tl.kth_path(u, v, k) << '\n'; { int w = rnd(0, n - 1); assert(lc.on_path(u, v, w) == @@ -39,23 +30,10 @@ int main() { lc.dist_edges(u, v))); } if (u != v) { - assert(tl.kth_path(u, v, 0) == u); - assert(lin_kth_path.kth_path(u, v, 0) == u); assert( tl.kth_path(u, v, 1) == lc.next_on_path(u, v)); - assert(lin_kth_path.kth_path(u, v, 1) == - lc.next_on_path(u, v)); assert(tl.kth_path(u, v, dist_in_edges - 1) == lc.next_on_path(v, u)); - assert( - lin_kth_path.kth_path(u, v, dist_in_edges - 1) == - lc.next_on_path(v, u)); - assert(tl.kth_path(u, v, dist_in_edges) == v); - assert( - lin_kth_path.kth_path(u, v, dist_in_edges) == v); - assert(tl.kth_path(u, v, dist_in_edges + 1) == -1); - assert(lin_kth_path.kth_path(u, v, - dist_in_edges + 1) == -1); } } } diff --git a/tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp b/tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp index 21241b55..26babb98 100644 --- a/tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp +++ b/tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp @@ -1,5 +1,7 @@ #define PROBLEM \ "https://judge.yosupo.jp/problem/rooted_tree_isomorphism_classification" +// as std::map insert takes O(n) time in debug mode +#undef _GLIBCXX_DEBUG #include "../template.hpp" #include "../../../library/trees/subtree_isomorphism.hpp" int main() { diff --git a/tests/scripts/ptc.sh b/tests/scripts/ptc.sh index d3684eb7..196bce8b 100755 --- a/tests/scripts/ptc.sh +++ b/tests/scripts/ptc.sh @@ -10,28 +10,33 @@ echo "DON'T PUSH ANY OF THESE CHANGES TO THE REPO!!!!!!!!" echo "if you push these changes, I'll slap your butt" # remove some files not suitable for PDF: -rm ../library/data_structures/bit_uncommon/rupq.hpp -rm ../library/data_structures/bit_uncommon/rurq.hpp -rm ../library/data_structures/seg_tree.png -rm ../library/data_structures/seg_tree_uncommon/distinct_query.hpp -rm ../library/data_structures/seg_tree_uncommon/implicit.hpp -rm ../library/data_structures/seg_tree_uncommon/kth_smallest_query.hpp -rm ../library/data_structures/uncommon/mode_query.hpp -rm ../library/data_structures/uncommon/priority_queue_of_updates.hpp -rm ../library/graphs/strongly_connected_components/add_edges_strongly_connected.hpp -rm ../library/graphs/functional_graph_processor.hpp -rm ../library/math/derangements.hpp -rm ../library/math/num_distinct_subsequences.hpp -rm ../library/math/partitions.hpp -rm ../library/monotonic_stack/cartesian_k_ary_tree.hpp -rm ../library/monotonic_stack/max_rect_histogram.hpp -rm ../library/monotonic_stack/cartesian_binary_tree_after.png -rm ../library/monotonic_stack/mono_stack_ri.png -rm ../library/strings/manacher/longest_palindrome_query.hpp -rm -rf ../library/trees/centroid_decomp_uncommon/ -rm -rf ../library/trees/edge_centroid_decomp_uncommon/ -rm -rf ../library/trees/ladder_decomposition/ladder_decomposition.hpp -rm ../library/trees/linear_kth_path.hpp +rm ../library/data_structures/bit_uncommon/rupq.hpp || exit 1 +rm ../library/data_structures/bit_uncommon/rurq.hpp || exit 1 +rm ../library/data_structures/seg_tree.png || exit 1 +rm ../library/data_structures/seg_tree_uncommon/distinct_query.hpp || exit 1 +rm ../library/data_structures/seg_tree_uncommon/implicit.hpp || exit 1 +rm ../library/data_structures/seg_tree_uncommon/kth_smallest_query.hpp || exit 1 +rm ../library/data_structures/uncommon/mode_query.hpp || exit 1 +rm ../library/data_structures/uncommon/priority_queue_of_updates.hpp || exit 1 +rm ../library/graphs/scc/add_edges_strongly_connected.hpp || exit 1 +rm ../library/graphs/functional_graph_processor.hpp || exit 1 +rm ../library/math/derangements.hpp || exit 1 +rm ../library/math/num_distinct_subsequences.hpp || exit 1 +rm ../library/math/partitions.hpp || exit 1 +rm ../library/monotonic_stack/cartesian_k_ary_tree.hpp || exit 1 +rm ../library/monotonic_stack/max_rect_histogram.hpp || exit 1 +rm ../library/monotonic_stack/cartesian_binary_tree_after.png || exit 1 +rm ../library/monotonic_stack/mono_stack_ri.png || exit 1 +rm ../library/strings/manacher/longest_palindrome_query.hpp || exit 1 +rm ../library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp || exit 1 +rm ../library/trees/centroid_decomp_uncommon/count_paths_per_node.hpp || exit 1 +rm ../library/trees/edge_centroid_decomp_uncommon/README.md || exit 1 +rm ../library/trees/edge_centroid_decomp_uncommon/contour_range_query.hpp || exit 1 +rm ../library/trees/edge_centroid_decomp_uncommon/contour_range_update.hpp || exit 1 +rm ../library/trees/edge_centroid_decomp_uncommon/count_paths_per_length.hpp || exit 1 +rm ../library/trees/edge_centroid_decomp_uncommon/sum_adjacent.hpp || exit 1 +rm ../library/trees/ladder_decomposition/ladder_decomposition.hpp || exit 1 +rm ../library/trees/linear_kth_path.hpp || exit 1 # remove links in comments: these aren't useful in the PDF, and are usually the # longest words which extend into the next column