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
14 changes: 1 addition & 13 deletions .verify-helper/timestamps.remote.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"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": "2025-02-10 14:50:36 -0700",
"tests/library_checker_aizu_tests/data_structures/pq_ds_undo_with_dsu.test.cpp": "2025-02-10 14:50:36 -0700",
"tests/library_checker_aizu_tests/data_structures/range_parallel_dsu.test.cpp": "2025-08-28 13:19:16 -0600",
"tests/library_checker_aizu_tests/data_structures/rmq_disjoint_sparse_table.test.cpp": "2024-12-15 14:34:10 -0600",
"tests/library_checker_aizu_tests/data_structures/rmq_linear.test.cpp": "2025-08-14 12:01:15 -0600",
"tests/library_checker_aizu_tests/data_structures/rmq_sparse_table.test.cpp": "2025-08-14 12:01:15 -0600",
Expand All @@ -65,20 +64,18 @@
"tests/library_checker_aizu_tests/graphs/hopcroft_karp_aizu.test.cpp": "2025-08-14 10:27:46 -0600",
"tests/library_checker_aizu_tests/graphs/hopcroft_karp_lib_checker.test.cpp": "2025-08-14 10:27:46 -0600",
"tests/library_checker_aizu_tests/graphs/mst.test.cpp": "2025-08-22 13:27:42 -0600",
"tests/library_checker_aizu_tests/graphs/offline_incremental_scc.test.cpp": "2025-08-28 13:19:16 -0600",
"tests/library_checker_aizu_tests/graphs/strongly_connected_components_aizu.test.cpp": "2025-08-14 10:27:46 -0600",
"tests/library_checker_aizu_tests/graphs/strongly_connected_components_lib_checker.test.cpp": "2025-08-14 10:27:46 -0600",
"tests/library_checker_aizu_tests/graphs/two_edge_components.test.cpp": "2025-08-14 10:27:46 -0600",
"tests/library_checker_aizu_tests/handmade_tests/count_paths.test.cpp": "2025-08-28 13:57:36 -0600",
"tests/library_checker_aizu_tests/handmade_tests/dsu.test.cpp": "2025-08-22 13:14:15 -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/edge_cd_small_trees.test.cpp": "2025-08-28 13:19:16 -0600",
"tests/library_checker_aizu_tests/handmade_tests/fib_matrix_expo.test.cpp": "2025-08-28 13:19:16 -0600",
"tests/library_checker_aizu_tests/handmade_tests/functional_graph.test.cpp": "2025-08-06 16:18:37 -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": "2025-08-04 17:01:28 -0600",
"tests/library_checker_aizu_tests/handmade_tests/mobius.test.cpp": "2025-02-10 14:50:36 -0700",
"tests/library_checker_aizu_tests/handmade_tests/mod_int.test.cpp": "2025-08-28 13:19:16 -0600",
"tests/library_checker_aizu_tests/handmade_tests/mod_division.test.cpp": "2025-09-07 15:15:17 -0600",
"tests/library_checker_aizu_tests/handmade_tests/n_choose_k.test.cpp": "2025-08-28 13:19:16 -0600",
"tests/library_checker_aizu_tests/handmade_tests/permutation_tree_small.test.cpp": "2025-08-14 12:01:15 -0600",
"tests/library_checker_aizu_tests/handmade_tests/rmq_small_n.test.cpp": "2025-08-14 12:01:15 -0600",
Expand All @@ -89,21 +86,14 @@
"tests/library_checker_aizu_tests/loops/quotients.test.cpp": "2024-11-17 14:04:03 -0600",
"tests/library_checker_aizu_tests/loops/submasks.test.cpp": "2025-02-10 14:50:36 -0700",
"tests/library_checker_aizu_tests/loops/supermasks.test.cpp": "2025-02-10 14:50:36 -0700",
"tests/library_checker_aizu_tests/math/binary_exponentiation_mod.test.cpp": "2025-08-28 13:19:16 -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": "2025-08-28 13:19:16 -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": "2025-08-28 13:19:16 -0600",
"tests/library_checker_aizu_tests/math/matrix_mult.test.cpp": "2024-11-17 14:04:03 -0600",
"tests/library_checker_aizu_tests/math/mod_int_derangement.test.cpp": "2025-08-28 13:19:16 -0600",
"tests/library_checker_aizu_tests/math/mod_int_gcd_convolution.test.cpp": "2025-08-28 13:19:16 -0600",
"tests/library_checker_aizu_tests/math/mod_int_n_choose_k.test.cpp": "2025-08-28 13:19:16 -0600",
"tests/library_checker_aizu_tests/math/mod_int_tetration.test.cpp": "2025-08-28 13:19:16 -0600",
"tests/library_checker_aizu_tests/math/n_choose_k.test.cpp": "2025-08-28 13:19:16 -0600",
"tests/library_checker_aizu_tests/math/num_subsequences.test.cpp": "2024-11-17 14:04:03 -0600",
"tests/library_checker_aizu_tests/math/partitions.test.cpp": "2025-08-28 13:19:16 -0600",
"tests/library_checker_aizu_tests/math/prime_sieve.test.cpp": "2024-11-22 11:54:52 -0600",
"tests/library_checker_aizu_tests/math/solve_linear_mod.test.cpp": "2025-08-28 13:19:16 -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": "2025-08-04 20:35:27 -0600",
Expand Down Expand Up @@ -133,7 +123,6 @@
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_query.test.cpp": "2025-08-14 10:27:46 -0600",
"tests/library_checker_aizu_tests/trees/edge_cd_contour_range_update.test.cpp": "2025-08-14 10:27:46 -0600",
"tests/library_checker_aizu_tests/trees/edge_cd_count_paths_per_length.test.cpp": "2025-08-14 10:27:46 -0600",
"tests/library_checker_aizu_tests/trees/edge_cd_reroot_dp.test.cpp": "2025-08-28 13:19:16 -0600",
"tests/library_checker_aizu_tests/trees/hld_aizu1.test.cpp": "2025-08-24 19:27:23 -0600",
"tests/library_checker_aizu_tests/trees/hld_aizu2.test.cpp": "2025-08-24 19:27:23 -0600",
"tests/library_checker_aizu_tests/trees/hld_lib_checker_path.test.cpp": "2025-08-24 19:27:23 -0600",
Expand All @@ -145,6 +134,5 @@
"tests/library_checker_aizu_tests/trees/lca_all_methods_aizu.test.cpp": "2025-08-21 12:17:27 -0600",
"tests/library_checker_aizu_tests/trees/lca_all_methods_lib_checker.test.cpp": "2025-08-21 12:17:27 -0600",
"tests/library_checker_aizu_tests/trees/shallowest_aizu_tree_height.test.cpp": "2025-09-03 10:32:09 -0600",
"tests/library_checker_aizu_tests/trees/shallowest_lib_checker_tree_path_composite.test.cpp": "2025-09-03 10:32:09 -0600",
"tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp": "2025-08-14 10:27:46 -0600"
}
26 changes: 14 additions & 12 deletions library/math/matrix_related/row_reduce.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "../mod_int.hpp"
#include "../mod_division.hpp"
//! @code
//! auto [rank, det] = row_reduce(mat, cols);
//! @endcode
Expand All @@ -8,28 +8,30 @@
//! affected by row operations
//! @time O(n * m * min(cols, n))
//! @space O(1)
pair<int, mint> row_reduce(vector<vector<mint>>& mat,
int cols) {
pii row_reduce(vector<vi>& mat, int cols) {
int n = sz(mat), m = sz(mat[0]), rank = 0;
mint det = 1;
int det = 1;
for (int col = 0; col < cols && rank < n; col++) {
auto it = find_if(rank + all(mat),
[&](auto& v) { return v[col].x; });
[&](auto& v) { return v[col]; });
if (it == end(mat)) {
det = 0;
continue;
}
if (it != begin(mat) + rank) {
det = mint(0) - det;
det = (mod - det) % mod;
iter_swap(begin(mat) + rank, it);
}
det = det * mat[rank][col];
mint a_inv = mint(1) / mat[rank][col];
for (mint& num : mat[rank]) num = num * a_inv;
rep(i, 0, n) if (i != rank && mat[i][col].x != 0) {
mint num = mat[i][col];
det = 1LL * det * mat[rank][col] % mod;
int a_inv = mod_div(1, mat[rank][col]);
for (int& num : mat[rank])
num = 1LL * num * a_inv % mod;
rep(i, 0, n) if (i != rank && mat[i][col] != 0) {
int num = mat[i][col];
rep(j, 0, m) mat[i][j] =
mat[i][j] - mat[rank][j] * num;
((mat[i][j] - 1LL * mat[rank][j] * num) % mod +
mod) %
mod;
}
rank++;
}
Expand Down
14 changes: 6 additions & 8 deletions library/math/matrix_related/solve_linear_mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@
//! @time O(n * m * min(n, m))
//! @space O(m)
struct solve_linear_mod {
int rank;
mint det;
vector<mint> sol;
solve_linear_mod(vector<vector<mint>>& mat,
const vector<mint>& rhs) {
int rank, det;
vi sol;
solve_linear_mod(vector<vi>& mat, const vi& rhs) {
int n = sz(mat), m = sz(mat[0]);
rep(i, 0, n) mat[i].push_back(rhs[i]);
tie(rank, det) = row_reduce(mat, m);
if (any_of(rank + all(mat),
[](auto& v) { return v.back().x; })) {
[](vi& v) { return v.back(); })) {
return;
}
sol.resize(m);
int j = 0;
for_each(begin(mat), begin(mat) + rank, [&](auto& v) {
while (v[j].x == 0) j++;
for_each(begin(mat), begin(mat) + rank, [&](vi& v) {
while (!v[j]) j++;
sol[j] = v.back();
});
}
Expand Down
8 changes: 8 additions & 0 deletions library/math/mod_division.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once
const int mod = 998244353;
int mod_div(int x, int y) {
int m = mod, u = 1, v = 0;
while (m) swap(u -= y / m * v, v), swap(y %= m, m);
assert(y == 1);
return 1LL * x * (u + mod) % mod;
}
12 changes: 0 additions & 12 deletions library/math/mod_int.hpp

This file was deleted.

9 changes: 0 additions & 9 deletions library/math/mod_int_division.hpp

This file was deleted.

12 changes: 0 additions & 12 deletions library/math/mod_int_pow.hpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@
#include "../template.hpp"
#include "../../../library/data_structures/dsu/range_parallel_dsu.hpp"
#include "../../../library/data_structures/dsu/range_parallel_equivalence_classes.hpp"
#include "../../../library/math/mod_int.hpp"
const int mod = 998244353;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, q;
cin >> n >> q;
rp_dsu dsu(n);
vector<mint> y(n);
for (int i = 0; i < n; i++) {
int num;
cin >> num;
y[i] = num;
}
vector<mint> x = y;
mint ans = 0;
vi y(n);
for (int i = 0; i < n; i++) cin >> y[i];
vi x = y;
int ans = 0;
auto f = [&](int u, int v) {
ans = ans + x[u] * x[v];
x[u] = x[u] + x[v];
ans = (ans + 1LL * x[u] * x[v]) % mod;
x[u] = (x[u] + x[v]) % mod;
};
vector<array<int, 3>> queries;
queries.reserve(q);
Expand All @@ -29,18 +25,19 @@ int main() {
cin >> k >> a >> b;
dsu.join(a, b, k, f);
queries.push_back({a, b, k});
cout << ans.x << '\n';
cout << ans << '\n';
if (qq == 0 || qq == 1 || qq == 10 || qq == 1000 ||
qq == 100'000 || qq == q - 1) {
auto uf = get_rp_dsu(queries, n);
vector<mint> sums(n);
mint offline_ans = 0;
vi sums(n);
int offline_ans = 0;
for (int i = 0; i < n; i++) {
int id = uf.find(i);
offline_ans = offline_ans + sums[id] * y[i];
sums[id] = sums[id] + y[i];
offline_ans =
(offline_ans + 1LL * sums[id] * y[i]) % mod;
sums[id] = (sums[id] + y[i]) % mod;
}
assert(ans.x == offline_ans.x);
assert(ans == offline_ans);
}
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#include "../template.hpp"
#include "../../../library/graphs/strongly_connected_components/offline_incremental_scc.hpp"
#include "../../../library/data_structures/dsu/dsu.hpp"
#include "../../../library/math/mod_int.hpp"
const int mod = 998244353;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<mint> xs(n);
for (int i = 0; i < n; i++) cin >> xs[i].x;
vector<int> xs(n);
for (int i = 0; i < n; i++) cin >> xs[i];
vector<array<int, 2>> eds(m);
for (auto& [u, v] : eds) cin >> u >> v;
auto joins = offline_incremental_scc(eds, n);
Expand All @@ -21,22 +21,22 @@ int main() {
ranges::sort(all(order), {},
[&](int i) { return joins[i]; });
DSU dsu(n);
mint sum = 0;
int sum = 0;
for (int t = 0, it = 0; t < m; t++) {
while (it < m && joins[order[it]] <= t) {
auto [u, v] = eds[order[it]];
u = dsu.go(u);
v = dsu.go(v);
if (dsu.e[u] > dsu.e[v]) swap(u, v);
if (u != v) {
sum = sum + xs[u] * xs[v];
xs[u] = xs[u] + xs[v];
sum = (sum + 1LL * xs[u] * xs[v]) % mod;
xs[u] = (xs[u] + xs[v]) % mod;
xs[v] = xs[u];
}
dsu.join(u, v);
it++;
}
cout << sum.x << '\n';
cout << sum << '\n';
}
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "../template.hpp"
#include "../edge_cd_asserts.hpp"
#include "../../../kactl/stress-tests/utilities/genTree.h"
#include "../../../library/math/mod_int_pow.hpp"
#include "../../../library/trees/edge_cd.hpp"
int main() {
{
Expand All @@ -21,7 +20,9 @@ int main() {
});
}
for (int n = 2; n <= 7; n++) {
int num_codes = mpow(n, n - 2).x;
int num_codes = 1;
for (int k = 0; k < n - 2; k++) num_codes *= n;
// int num_codes = mpow(n, n - 2).x;
vector<vector<int>> pruf_codes(num_codes,
vector<int>(n - 2));
for (int i = 0; i < num_codes; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#define PROBLEM \
"https://onlinejudge.u-aizu.ac.jp/problems/ITP1_1_A"
#include "../template.hpp"
#define const ;
#include "../../../library/math/mod_division.hpp"
#undef const
int main() {
cin.tie(0)->sync_with_stdio(0);
for (mod = 1; mod < 500; mod++) {
for (int x = 0; x < mod; x++) {
for (int y = 0; y < mod; y++) {
if (gcd(y, mod) == 1) {
int quotient = mod_div(x, y);
assert(1LL * quotient * y % mod == x);
}
}
}
}
cout << "Hello World\n";
return 0;
}
Loading
Loading