Skip to content

Commit

Permalink
More poly tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamant-pwn committed Nov 23, 2024
1 parent c6a5e57 commit f399599
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
30 changes: 30 additions & 0 deletions verify/poly/inter_geo.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @brief Polynomial Interpolation (Geometric Sequence)
#define PROBLEM "https://judge.yosupo.jp/problem/polynomial_interpolation_on_geometric_sequence"
#pragma GCC optimize("Ofast,unroll-loops")
#include "cp-algo/math/poly.hpp"
#include <bits/stdc++.h>

using namespace std;
using namespace cp_algo::math;

const int mod = 998244353;
using base = modint<mod>;
using polyn = poly_t<base>;

void solve() {
int n, a, r;
cin >> n >> a >> r;
vector<base> y(n);
copy_n(istream_iterator<base>(cin), n, begin(y));
polyn(y).chirpz_inverse(r, n).mulx(base(a).inv()).print(n);
}

signed main() {
//freopen("input.txt", "r", stdin);
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
while(t--) {
solve();
}
}
31 changes: 31 additions & 0 deletions verify/poly/multieval.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// @brief Multipoint Evaluation
#define PROBLEM "https://judge.yosupo.jp/problem/multipoint_evaluation"
#pragma GCC optimize("Ofast,unroll-loops")
#include "cp-algo/math/poly.hpp"
#include <bits/stdc++.h>

using namespace std;
using namespace cp_algo::math;

const int mod = 998244353;
using base = modint<mod>;
using polyn = poly_t<base>;

void solve() {
int n, m;
cin >> n >> m;
vector<base> f(n), x(m);
copy_n(istream_iterator<base>(cin), n, begin(f));
copy_n(istream_iterator<base>(cin), m, begin(x));
polyn(polyn(f).eval(x)).print(m);
}

signed main() {
//freopen("input.txt", "r", stdin);
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
while(t--) {
solve();
}
}
30 changes: 30 additions & 0 deletions verify/poly/multieval_geo.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @brief Multipoint Evaluation (Geometric Sequence)
#define PROBLEM "https://judge.yosupo.jp/problem/multipoint_evaluation_on_geometric_sequence"
#pragma GCC optimize("Ofast,unroll-loops")
#include "cp-algo/math/poly.hpp"
#include <bits/stdc++.h>

using namespace std;
using namespace cp_algo::math;

const int mod = 998244353;
using base = modint<mod>;
using polyn = poly_t<base>;

void solve() {
int n, m, a, r;
cin >> n >> m >> a >> r;
vector<base> f(n);
copy_n(istream_iterator<base>(cin), n, begin(f));
polyn(f).mulx(a).chirpz(r, m).print(m);
}

signed main() {
//freopen("input.txt", "r", stdin);
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
while(t--) {
solve();
}
}
39 changes: 39 additions & 0 deletions verify/poly/sampling.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @brief Shift of Sampling Points of Polynomial
#define PROBLEM "https://judge.yosupo.jp/problem/shift_of_sampling_points_of_polynomial"
#define CP_ALGO_MAXN 1 << 20
#pragma GCC optimize("Ofast,unroll-loops")
#include "cp-algo/math/poly.hpp"
#include <bits/stdc++.h>

using namespace std;
using namespace cp_algo::math;

const int mod = 998244353;
using base = modint<mod>;
using polyn = poly_t<base>;

// TODO: Use single-convolution approach
void solve() {
int n, m, c;
cin >> n >> m >> c;
vector<base> a(n);
copy_n(istream_iterator<base>(cin), n, begin(a));
polyn A = polyn(a);
polyn Q = polyn({1, -1}).pow(n, n + 1);
A -= ((A * Q).div_xk(n).mod_xk(m) * Q.inv(m)).mod_xk(m).mul_xk(n);
A = A.reverse(n + m);
polyn shift = polyn({1, -1}).pow(c, n).shift(1).mulx(-1);
auto R = (A.div_xk(n - 1) * shift) + (A.mod_xk(n - 1) * shift).div_xk(n - 1);
R.div_xk(1).reverse(m).print(m);
}

signed main() {
//freopen("input.txt", "r", stdin);
ios::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;// cin >> t;
while(t--) {
solve();
}
}

0 comments on commit f399599

Please sign in to comment.