0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-03 18:56:26 +00:00

P3803 【模板】多项式乘法(FFT)

https://www.luogu.com.cn/record/96299698
This commit is contained in:
Baoshuo Ren 2022-12-02 16:40:22 +08:00
parent cde051aa86
commit 3ea3640209
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -22,7 +22,9 @@ constexpr long long binpow(long long a, long long b) {
return res; return res;
} }
std::vector<long long> number_theoretic_transform(std::vector<long long> a) { void number_theoretic_transform(std::vector<long long> &a) {
if (a.size() == 1) return;
// assert(a.size() == (1 << std::__lg(a.size()))); // assert(a.size() == (1 << std::__lg(a.size())));
int k = std::__lg(a.size()); int k = std::__lg(a.size());
@ -55,8 +57,6 @@ std::vector<long long> number_theoretic_transform(std::vector<long long> a) {
} }
} }
} }
return a;
} }
class Poly : public std::vector<long long> { class Poly : public std::vector<long long> {
@ -81,15 +81,15 @@ class Poly : public std::vector<long long> {
std::vector<long long> f(*this), g(b); std::vector<long long> f(*this), g(b);
f.resize(k); f.resize(k);
f = number_theoretic_transform(f); number_theoretic_transform(f);
g.resize(k); g.resize(k);
g = number_theoretic_transform(g); number_theoretic_transform(g);
for (int i = 0; i < k; i++) { for (int i = 0; i < k; i++) {
f[i] = f[i] * g[i] % mod; f[i] = f[i] * g[i] % mod;
} }
f = number_theoretic_transform(f); number_theoretic_transform(f);
// assert(f.size() > 0) // assert(f.size() > 0)
std::reverse(f.begin() + 1, f.end()); std::reverse(f.begin() + 1, f.end());