rt,空间一直卡不进去,求助。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e6 + 5;
const long double PI = acos(-1), eps = 1e-12;
long long gb, gi, mod, n, c;
struct Couple {
double x, y;
inline friend Couple operator+(Couple x, Couple y) {
return Couple{x.x + y.x, x.y + y.y};
}
inline friend Couple operator-(Couple x, Couple y) {
return Couple{x.x - y.x, x.y - y.y};
}
inline friend Couple operator*(Couple x, Couple y) {
return Couple{x.x * y.x - x.y * y.y, x.y * y.x + x.x * y.y};
}
};
int rev[maxn];
Couple w[maxn];
void prepare(int len) {
for (int i = 1; i < len; i <<= 1)
for (int j = 0; j < i; j++)
w[len / i * j] = Couple{cos(PI / i * j), sin(PI / i * j)};
// cout << w[8].x << "asfdsadfasdsagdsgggdfdg " << w[8].y << " " << cos(PI / 2) << endl;
for (int i = 0; i < len; i++) {
rev[i] = rev[i >> 1] >> 1;
if(i & 1)
rev[i] = rev[i] | (len >> 1);
}
}
struct Poly1 {
vector<Couple> a;
inline int size() {
return a.size();
}
inline void resize(int N) {
a.resize(N);
}
inline Couple& operator[](int x) {
return a[x];
}
inline Couple get_Cp(int p, int f) {
return Couple{w[p].x, f * w[p].y};
}
void FFT(int f) {
int n = size();
for (int i = 0; i < n; i++)
if(i < rev[i])
swap(a[i], a[rev[i]]);
for (int h = 2; h <= n; h <<= 1) {
// cout << h << endl;
for (int i = 0; i < n; i += h) {
// cout << i << endl;
for (int j = i; j < i + h / 2; j++) {
// cout << j << endl;
// get_Cp(n / i * j, f);
// cout << j << endl;
// cout << i << " " << j << " " << get_Cp(n / (h >> 1) * (j - i), f).x << " " << get_Cp(n / (h >> 1) * (j - i), f).y << " " << n / (h >> 1) * (j - i) << endl;
Couple a0 = a[j], a1 = a[j + h / 2] * get_Cp(n / (h >> 1) * (j - i), f);
a[j] = (a0 + a1), a[j + h / 2] = (a0 - a1);
// cout << j << endl;
}
}
}
if(f == -1) {
for (int i = 0; i < n; i++)
a[i].x /= n;
}
}
void print() {
for (int i = 0; i < a.size(); i++)
cout << a[i].x << " ";
cout << endl;
}
} ;
Poly1 f1, f2, g1, g2;
Poly1 operator*(Poly1 &f, Poly1 &g) {
int len = 1, t = f.size() + g.size() - 1;
while(len < t)
len <<= 1;
prepare(len), f.resize(len), g.resize(len);
// f.print(), g.print();
f1.resize(0), f2.resize(0), g1.resize(0), g2.resize(0);
f1.resize(len), f2.resize(len), g1.resize(len), g2.resize(len);
int mo = sqrt(mod);
for (int i = 0; i < len; i++)
f1[i].x = (int)(f[i].x) / mo, f2[i].x = (int)f[i].x % mo,
g1[i].x = (int)(g[i].x) / mo, g2[i].x = (int)g[i].x % mo;
// f1.print(), f2.print(), g1.print(), g2.print();
f1.FFT(1), f2.FFT(1), g1.FFT(1), g2.FFT(1);
// f2.print(), g2.print();
for (int i = 0; i < len; i++) {
Couple t1 = f2[i] * g2[i], t2 = f1[i] * g1[i];
f2[i] = f2[i] * g1[i] + f1[i] * g2[i];
g1[i] = t1;
f1[i] = t2;
}
// cout << endl;
f1.FFT(-1), f2.FFT(-1), g1.FFT(-1);
// cout << 123 << endl;
// f1.print(), f2.print(), g1.print(), g2.print();
// cout << endl;
int MO = 1ll * mo * mo % mod;
for (int i = 0; i < len; i++)
f[i].x = (1ll * (long long)round(f1[i].x) % mod * MO % mod + 1ll * (long long)round(f2[i].x) % mod * mo % mod + (long long)round(g1[i].x) % mod), f[i].x = (long long)(round(f[i].x)) % mod;
f.resize(t);
// f.print();
return f;
}
int qpow(int x, int k, int p) {
int res = 1;
while(k) {
if(k & 1)
res = 1ll * res * x % p;
x = 1ll * x * x % p, k >>= 1;
}
return res;
}
int pw[maxn / 6], pi[maxn / 6], fac[maxn / 5000], tot;
int getroot(int n) {
int x = n - 1;
for (int i = 2; i * i <= x; i++) {
if(x % i == 0) {
fac[++tot] = i;
while(x % i == 0)
x /= i;
}
}
if(x > 1)
fac[++tot] = x;
for (int i = 2; i < n; i++) {
bool f = 1;
for (int j = 1; j <= tot; j++) {
if(qpow(i, (n - 1) / fac[j], n) == 1)
f = 0;
if(!f)
break;
}
if(f)
return i;
}
}
void prework() {
gb = getroot(mod);
pw[0] = 1;
for (int i = 1; i <= n; i++)
pw[i] = 1ll * pw[i - 1] * gb % mod;
gi = qpow(gb, n - 1, mod);
// cout << gb << " " << gi << endl;
pi[0] = 1;
for (int i = 1; i <= n; i++)
pi[i] = 1ll * pi[i - 1] * gi % mod;
}
Poly1 f, g;
int tx = 1;
int cal(int x) {
return 1ll * x * (x - 1) / 2 % n;
}
struct Poly2 {
vector<int> a;
int size() {
return a.size();
}
void resize(int N) {
a.resize(N);
}
int& operator[](int x) {
return a[x];
}
void DFT(int flag) {
int n = a.size();
f.resize(0), g.resize(0);
f.resize(n), g.resize(2 * n);
if(flag == 1) {
for (int i = 0; i < n; i++)
f[i].x = 1ll * a[i] * pi[cal(i)] % mod;
for (int i = 0; i < 2 * n; i++)
g[i].x = pw[cal(i)];
}
else {
for (int i = 0; i < n; i++)
f[i].x = 1ll * a[i] * pw[cal(i)] % mod;
for (int i = 0; i < 2 * n; i++)
g[i].x = pi[cal(i)];
}
// f.print();
reverse(f.a.begin(), f.a.end());
f = f * g;
for (int i = n - 1; i < 2 * n - 1; i++) {
if(flag == 1)
a[i - n + 1] = (long long)round(f[i].x) % mod * pi[cal(i - n + 1)] % mod;
else
a[i - n + 1] = (long long)round(f[i].x) % mod * pw[cal(i - n + 1)] % mod;
// if(tx)
// cout << (int)round(f[i].x) % mod << " " << a[i - n + 1] << endl;
}
if(flag == -1) {
int inv = qpow(n, mod - 2, mod);
for (int i = 0; i < n; i++)
a[i] = 1ll * a[i] * inv % mod;
}
// for (int i = 0; i < n; i++)
// cout << a[i] << " ";
// cout << endl;
}
} ft, gt;
signed main() {
// freopen("test.in", "r", stdin);
// freopen("baoli.out", "w", stdout);
ios::sync_with_stdio(false);
cin >> n >> c;
ft.resize(n), gt.resize(n);
mod = n + 1; prework();
// cout << gb << " " << qpow(gb, n, mod) << endl;
// cout << gb << endl;
for (int i = 0; i < n; i++)
cin >> ft[i], ft[i] %= mod;
for (int i = 0; i < n; i++)
cin >> gt[i], gt[i] %= mod;
ft.DFT(1), tx = 0, gt.DFT(1);
//for (int i = 0; i < n; i++)
// cout << f[i] << " ";
// cout << endl;
for (int i = 0; i < n; i++)
ft[i] = 1ll * ft[i] * qpow(gt[i], c, mod) % mod;
// cout << endl;
ft.DFT(-1);
for (int i = 0; i < n; i++)
cout << ft[i] << '\n';
return 0;
}