Skip to content

Commit f399599

Browse files
committedNov 23, 2024
More poly tests
1 parent c6a5e57 commit f399599

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed
 

‎verify/poly/inter_geo.test.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @brief Polynomial Interpolation (Geometric Sequence)
2+
#define PROBLEM "https://judge.yosupo.jp/problem/polynomial_interpolation_on_geometric_sequence"
3+
#pragma GCC optimize("Ofast,unroll-loops")
4+
#include "cp-algo/math/poly.hpp"
5+
#include <bits/stdc++.h>
6+
7+
using namespace std;
8+
using namespace cp_algo::math;
9+
10+
const int mod = 998244353;
11+
using base = modint<mod>;
12+
using polyn = poly_t<base>;
13+
14+
void solve() {
15+
int n, a, r;
16+
cin >> n >> a >> r;
17+
vector<base> y(n);
18+
copy_n(istream_iterator<base>(cin), n, begin(y));
19+
polyn(y).chirpz_inverse(r, n).mulx(base(a).inv()).print(n);
20+
}
21+
22+
signed main() {
23+
//freopen("input.txt", "r", stdin);
24+
ios::sync_with_stdio(0);
25+
cin.tie(0);
26+
int t = 1;
27+
while(t--) {
28+
solve();
29+
}
30+
}

‎verify/poly/multieval.test.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// @brief Multipoint Evaluation
2+
#define PROBLEM "https://judge.yosupo.jp/problem/multipoint_evaluation"
3+
#pragma GCC optimize("Ofast,unroll-loops")
4+
#include "cp-algo/math/poly.hpp"
5+
#include <bits/stdc++.h>
6+
7+
using namespace std;
8+
using namespace cp_algo::math;
9+
10+
const int mod = 998244353;
11+
using base = modint<mod>;
12+
using polyn = poly_t<base>;
13+
14+
void solve() {
15+
int n, m;
16+
cin >> n >> m;
17+
vector<base> f(n), x(m);
18+
copy_n(istream_iterator<base>(cin), n, begin(f));
19+
copy_n(istream_iterator<base>(cin), m, begin(x));
20+
polyn(polyn(f).eval(x)).print(m);
21+
}
22+
23+
signed main() {
24+
//freopen("input.txt", "r", stdin);
25+
ios::sync_with_stdio(0);
26+
cin.tie(0);
27+
int t = 1;
28+
while(t--) {
29+
solve();
30+
}
31+
}

‎verify/poly/multieval_geo.test.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @brief Multipoint Evaluation (Geometric Sequence)
2+
#define PROBLEM "https://judge.yosupo.jp/problem/multipoint_evaluation_on_geometric_sequence"
3+
#pragma GCC optimize("Ofast,unroll-loops")
4+
#include "cp-algo/math/poly.hpp"
5+
#include <bits/stdc++.h>
6+
7+
using namespace std;
8+
using namespace cp_algo::math;
9+
10+
const int mod = 998244353;
11+
using base = modint<mod>;
12+
using polyn = poly_t<base>;
13+
14+
void solve() {
15+
int n, m, a, r;
16+
cin >> n >> m >> a >> r;
17+
vector<base> f(n);
18+
copy_n(istream_iterator<base>(cin), n, begin(f));
19+
polyn(f).mulx(a).chirpz(r, m).print(m);
20+
}
21+
22+
signed main() {
23+
//freopen("input.txt", "r", stdin);
24+
ios::sync_with_stdio(0);
25+
cin.tie(0);
26+
int t = 1;
27+
while(t--) {
28+
solve();
29+
}
30+
}

‎verify/poly/sampling.test.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// @brief Shift of Sampling Points of Polynomial
2+
#define PROBLEM "https://judge.yosupo.jp/problem/shift_of_sampling_points_of_polynomial"
3+
#define CP_ALGO_MAXN 1 << 20
4+
#pragma GCC optimize("Ofast,unroll-loops")
5+
#include "cp-algo/math/poly.hpp"
6+
#include <bits/stdc++.h>
7+
8+
using namespace std;
9+
using namespace cp_algo::math;
10+
11+
const int mod = 998244353;
12+
using base = modint<mod>;
13+
using polyn = poly_t<base>;
14+
15+
// TODO: Use single-convolution approach
16+
void solve() {
17+
int n, m, c;
18+
cin >> n >> m >> c;
19+
vector<base> a(n);
20+
copy_n(istream_iterator<base>(cin), n, begin(a));
21+
polyn A = polyn(a);
22+
polyn Q = polyn({1, -1}).pow(n, n + 1);
23+
A -= ((A * Q).div_xk(n).mod_xk(m) * Q.inv(m)).mod_xk(m).mul_xk(n);
24+
A = A.reverse(n + m);
25+
polyn shift = polyn({1, -1}).pow(c, n).shift(1).mulx(-1);
26+
auto R = (A.div_xk(n - 1) * shift) + (A.mod_xk(n - 1) * shift).div_xk(n - 1);
27+
R.div_xk(1).reverse(m).print(m);
28+
}
29+
30+
signed main() {
31+
//freopen("input.txt", "r", stdin);
32+
ios::sync_with_stdio(0);
33+
cin.tie(0);
34+
int t;
35+
t = 1;// cin >> t;
36+
while(t--) {
37+
solve();
38+
}
39+
}

0 commit comments

Comments
 (0)