Skip to content

Commit 7875040

Browse files
committed
fixed some tests
1 parent 8884bac commit 7875040

10 files changed

+52
-166
lines changed

tests/library_checker_aizu_tests/data_structures/range_parallel_dsu.test.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,19 @@
44
#include "../template.hpp"
55
#include "../../../library/data_structures/dsu/range_parallel_dsu.hpp"
66
#include "../../../library/data_structures/dsu/range_parallel_equivalence_classes.hpp"
7-
#include "../../../library/math/mod_int.hpp"
7+
const int mod = 998244353;
88
int main() {
99
cin.tie(0)->sync_with_stdio(0);
1010
int n, q;
1111
cin >> n >> q;
1212
rp_dsu dsu(n);
13-
vector<mint> y(n);
14-
for (int i = 0; i < n; i++) {
15-
int num;
16-
cin >> num;
17-
y[i] = num;
18-
}
19-
vector<mint> x = y;
20-
mint ans = 0;
13+
vi y(n);
14+
for (int i = 0; i < n; i++) cin >> y[i];
15+
vi x = y;
16+
int ans = 0;
2117
auto f = [&](int u, int v) {
22-
ans = ans + x[u] * x[v];
23-
x[u] = x[u] + x[v];
18+
ans = (ans + 1LL * x[u] * x[v]) % mod;
19+
x[u] = (x[u] + x[v]) % mod;
2420
};
2521
vector<array<int, 3>> queries;
2622
queries.reserve(q);
@@ -29,18 +25,19 @@ int main() {
2925
cin >> k >> a >> b;
3026
dsu.join(a, b, k, f);
3127
queries.push_back({a, b, k});
32-
cout << ans.x << '\n';
28+
cout << ans << '\n';
3329
if (qq == 0 || qq == 1 || qq == 10 || qq == 1000 ||
3430
qq == 100'000 || qq == q - 1) {
3531
auto uf = get_rp_dsu(queries, n);
36-
vector<mint> sums(n);
37-
mint offline_ans = 0;
32+
vi sums(n);
33+
int offline_ans = 0;
3834
for (int i = 0; i < n; i++) {
3935
int id = uf.find(i);
40-
offline_ans = offline_ans + sums[id] * y[i];
41-
sums[id] = sums[id] + y[i];
36+
offline_ans =
37+
(offline_ans + 1LL * sums[id] * y[i]) % mod;
38+
sums[id] = (sums[id] + y[i]) % mod;
4239
}
43-
assert(ans.x == offline_ans.x);
40+
assert(ans == offline_ans);
4441
}
4542
}
4643
return 0;

tests/library_checker_aizu_tests/graphs/offline_incremental_scc.test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
#include "../template.hpp"
44
#include "../../../library/graphs/strongly_connected_components/offline_incremental_scc.hpp"
55
#include "../../../library/data_structures/dsu/dsu.hpp"
6-
#include "../../../library/math/mod_int.hpp"
6+
const int mod = 998244353;
77
int main() {
88
cin.tie(0)->sync_with_stdio(0);
99
int n, m;
1010
cin >> n >> m;
11-
vector<mint> xs(n);
12-
for (int i = 0; i < n; i++) cin >> xs[i].x;
11+
vector<int> xs(n);
12+
for (int i = 0; i < n; i++) cin >> xs[i];
1313
vector<array<int, 2>> eds(m);
1414
for (auto& [u, v] : eds) cin >> u >> v;
1515
auto joins = offline_incremental_scc(eds, n);
@@ -21,22 +21,22 @@ int main() {
2121
ranges::sort(all(order), {},
2222
[&](int i) { return joins[i]; });
2323
DSU dsu(n);
24-
mint sum = 0;
24+
int sum = 0;
2525
for (int t = 0, it = 0; t < m; t++) {
2626
while (it < m && joins[order[it]] <= t) {
2727
auto [u, v] = eds[order[it]];
2828
u = dsu.go(u);
2929
v = dsu.go(v);
3030
if (dsu.e[u] > dsu.e[v]) swap(u, v);
3131
if (u != v) {
32-
sum = sum + xs[u] * xs[v];
33-
xs[u] = xs[u] + xs[v];
32+
sum = (sum + 1LL * xs[u] * xs[v]) % mod;
33+
xs[u] = (xs[u] + xs[v]) % mod;
3434
xs[v] = xs[u];
3535
}
3636
dsu.join(u, v);
3737
it++;
3838
}
39-
cout << sum.x << '\n';
39+
cout << sum << '\n';
4040
}
4141
return 0;
4242
}

tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "../template.hpp"
44
#include "../edge_cd_asserts.hpp"
55
#include "../../../kactl/stress-tests/utilities/genTree.h"
6-
#include "../../../library/math/mod_int_pow.hpp"
76
#include "../../../library/trees/edge_cd.hpp"
87
int main() {
98
{
@@ -21,7 +20,9 @@ int main() {
2120
});
2221
}
2322
for (int n = 2; n <= 7; n++) {
24-
int num_codes = mpow(n, n - 2).x;
23+
int num_codes = 1;
24+
for (int k = 0; k < n - 2; k++) num_codes *= n;
25+
// int num_codes = mpow(n, n - 2).x;
2526
vector<vector<int>> pruf_codes(num_codes,
2627
vector<int>(n - 2));
2728
for (int i = 0; i < num_codes; i++) {

tests/library_checker_aizu_tests/handmade_tests/mod_int.test.cpp

Lines changed: 0 additions & 72 deletions
This file was deleted.

tests/library_checker_aizu_tests/math/binary_exponentiation_mod.test.cpp

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/library_checker_aizu_tests/math/mod_int_derangement.test.cpp

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/library_checker_aizu_tests/math/mod_int_gcd_convolution.test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#define PROBLEM \
22
"https://judge.yosupo.jp/problem/gcd_convolution"
33
#include "../template.hpp"
4-
#include "../../../library/math/mod_int.hpp"
54
istream& operator>>(istream& is, vector<int>& v) {
65
for (int i = 1; i < sz(v); i++) is >> v[i];
76
return is;

tests/library_checker_aizu_tests/math/mod_int_n_choose_k.test.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
#define PROBLEM \
22
"https://judge.yosupo.jp/problem/binomial_coefficient_prime_mod"
33
#include "../template.hpp"
4-
// trick to remove const so I can use arbitrary prime mode
5-
// here
6-
#define const ;
7-
#include "../../../library/math/mod_int.hpp"
8-
#undef const
94
int main() {
105
cin.tie(0)->sync_with_stdio(0);
11-
int t;
6+
int t, mod;
127
cin >> t >> mod;
138
const int mx_n = min(int(1e7), mod);
14-
vector<mint> fact(mx_n, 1);
9+
vector<int> fact(mx_n, 1);
1510
for (int i = 2; i < mx_n; i++) fact[i] = fact[i - 1] * i;
1611
vector<mint> inv_fact(mx_n, 1);
1712
inv_fact.back() = mint(1) / fact.back();

tests/library_checker_aizu_tests/math/mod_int_tetration.test.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
"https://judge.yosupo.jp/problem/tetration_mod"
33
#include "../template.hpp"
44
#include "../../../library/math/totient.hpp"
5-
// trick to remove const so I can use arbitrary prime mode
6-
// here
7-
#define const ;
8-
#include "../../../library/math/mod_int_pow.hpp"
9-
#undef const
105
int mod_int_tetration(int b, int e, int local_mod) {
116
if (local_mod == 1) return 0;
127
if (b == 0) return (e + 1) % 2 % local_mod;

tests/library_checker_aizu_tests/trees/shallowest_lib_checker_tree_path_composite.test.cpp

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
#undef _GLIBCXX_DEBUG
44
#include "../template.hpp"
55
#include "../../../library/trees/shallowest_decomp_tree.hpp"
6-
#include "../../../library/math/mod_int.hpp"
7-
using line = array<mint, 2>;
6+
const int mod = 998244353;
7+
using line = array<int, 2>;
88
// returns f(g(x)) = f[0]*(g[0]*x+g[1]) + f[1]
99
line compose(line f, line g) {
10-
return {f[0] * g[0], f[1] + f[0] * g[1]};
10+
return {int(1LL * f[0] * g[0] % mod),
11+
int((f[1] + 1LL * f[0] * g[1]) % mod)};
1112
}
1213
int main() {
1314
cin.tie(0)->sync_with_stdio(0);
1415
int n;
1516
cin >> n;
16-
vector<mint> a(n);
17-
for (int i = 0; i < n; i++) cin >> a[i].x;
17+
vector<int> a(n);
18+
for (int i = 0; i < n; i++) cin >> a[i];
1819
vector<vector<int>> adj(n);
1920
vector<vector<line>> weight(n);
2021
for (int i = 0; i < n - 1; i++) {
@@ -25,30 +26,36 @@ int main() {
2526
weight[u].push_back({b, c});
2627
weight[v].push_back({b, c});
2728
}
28-
vector<mint> res(n);
29-
for (int i = 0; i < n; i++) res[i] = a[i];
29+
vector<int> res(a);
3030
shallowest(adj, [&](int cent) {
3131
assert(ssize(adj[cent]) == ssize(weight[cent]));
32-
mint total_sum_evaluated = 0;
32+
int total_sum_evaluated = 0;
3333
int total_cnt_nodes = 0;
34-
mint curr_sum_evaluated = 0;
34+
int curr_sum_evaluated = 0;
3535
int curr_cnt_nodes = 0;
3636
auto dfs = [&](auto&& self, int v, int p,
3737
line downwards, line upwards,
3838
bool forwards) -> void {
3939
// f(x) + f(y) + f(z) = b*x+c + b*y+c + b*z+c =
4040
// b*(x+y+z) + c*3
41-
res[v] = res[v] + upwards[0] * total_sum_evaluated +
42-
upwards[1] * total_cnt_nodes;
41+
res[v] =
42+
(res[v] + 1LL * upwards[0] * total_sum_evaluated +
43+
1LL * upwards[1] * total_cnt_nodes) %
44+
mod;
4345
if (forwards) {
44-
res[v] =
45-
res[v] + upwards[0] * a[cent] + upwards[1];
46+
res[v] = (res[v] + 1LL * upwards[0] * a[cent] +
47+
upwards[1]) %
48+
mod;
4649
res[cent] =
47-
res[cent] + downwards[0] * a[v] + downwards[1];
50+
(res[cent] + 1LL * downwards[0] * a[v] +
51+
downwards[1]) %
52+
mod;
4853
}
4954
curr_cnt_nodes++;
50-
curr_sum_evaluated = curr_sum_evaluated +
51-
downwards[0] * a[v] + downwards[1];
55+
curr_sum_evaluated =
56+
(curr_sum_evaluated + 1LL * downwards[0] * a[v] +
57+
downwards[1]) %
58+
mod;
5259
for (int i = 0; i < ssize(adj[v]); i++) {
5360
int u = adj[v][i];
5461
line curr_line = weight[v][i];
@@ -64,7 +71,7 @@ int main() {
6471
dfs(dfs, adj[cent][i], cent, weight[cent][i],
6572
weight[cent][i], 1);
6673
total_sum_evaluated =
67-
total_sum_evaluated + curr_sum_evaluated;
74+
(total_sum_evaluated + curr_sum_evaluated) % mod;
6875
total_cnt_nodes += curr_cnt_nodes;
6976
}
7077
total_sum_evaluated = 0;
@@ -75,7 +82,7 @@ int main() {
7582
dfs(dfs, adj[cent][i], cent, weight[cent][i],
7683
weight[cent][i], 0);
7784
total_sum_evaluated =
78-
total_sum_evaluated + curr_sum_evaluated;
85+
(total_sum_evaluated + curr_sum_evaluated) % mod;
7986
total_cnt_nodes += curr_cnt_nodes;
8087
}
8188
for (int v : adj[cent]) {
@@ -88,6 +95,6 @@ int main() {
8895
}
8996
}
9097
});
91-
for (int i = 0; i < n; i++) cout << res[i].x << ' ';
98+
for (int i = 0; i < n; i++) cout << res[i] << ' ';
9299
cout << '\n';
93100
}

0 commit comments

Comments
 (0)