#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const double Pi = acos(-1.0);
const int N = 3e5+5;
int n, m, f[N], len = 1, lim;
struct Complex {
double a, b;
Complex (double _a = 0, double _b = 0) { a = _a, b = _b; }
} a[N], b[N], Omega[30];
Complex operator + (const Complex &x, const Complex &y) {
return Complex(x. a + y. a, x. b + y. b); }
Complex operator - (const Complex &x, const Complex &y) {
return Complex(x. a - y. a, x. b - y. b); }
Complex operator * (const Complex &x, const Complex &y) {
return Complex(x. a * y. a - x. b * y. b, x. b * y. a + x. a * y. b); }
inline Complex Conj(Complex z) {
return Complex(z. a, -z. b);
}
inline int read() {
int s=0, w=1;
char ch=getchar();
while (ch<'0' || ch>'9') {
if (ch == '-') w = -w;
ch=getchar();
}
while (ch>='0' && ch<='9')
s = s*10 + ch-'0', ch=getchar();
return s*w;
}
void write1(int x) {
if (x < 0) putchar (45), x = -x;
if (x > 9) write1(x / 10);
putchar(x % 10 + 48);
}
void FFT(Complex *a, int n, bool op) {
for (int i=0; i<n; i++)
if (i < f[i]) swap(a[i], a[f[i]]);
for (int m=1, t=0; m<n; m<<=1, t++) {
Complex omega = op ? Conj(Omega[t]) : Omega[t];
for (int i=0; i<n; i+=m<<1) {
Complex x = Complex(1, 0);
for (int j=0; j<m; j++, x=x*omega) {
Complex tmp = x * a[i + j + m];
a[i + j + m] = a[i + j] - tmp;
a[i + j] = a[i + j] + tmp;
}
}
}
}
int main() {
cin >> n >> m;
for (int i=0; i<=n; i++)
a[i]. a = read();
for (int i=0; i<=m; i++)
b[i]. a = read();
n += m;
while (len <= n) ++lim, len <<= 1;
Omega[lim] = Complex(cos(Pi / len), sin(Pi / len));
for (int i=lim-1; ~i; i--)
Omega[i] = Omega[i+1] * Omega[i+1];
/* Omega[0] = Complex(1, 0),
Omega[1] = Complex(cos(2 * Pi / len), sin(2 * Pi / len));
for (int i=2; i<len; i++)
Omega[i] = Omega[i-1] * Omega[1]; */
for (int i=0; i<len; i++)
f[i] = f[i >> 1] >> 1 | (i & 1) << lim - 1;
FFT(a, len, 0), FFT(b, len, 0);
for (int i=0; i<len; i++)
a[i] = a[i] * b[i];
FFT(a, len, 1);
for (int i=0; i<=n; i++)
write1((int) (a[i]. a / len + 0.5)), putchar (' ');
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Subtask #1 Testcase #1 | 1.068 ms | 9 MB + 200 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #2 | 38.755 ms | 11 MB + 628 KB | Accepted | Score: 100 | 显示更多 |
Subtask #1 Testcase #3 | 16.506 ms | 9 MB + 992 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #4 | 16.596 ms | 9 MB + 980 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #5 | 1.051 ms | 9 MB + 200 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #6 | 1.046 ms | 9 MB + 200 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #7 | 1.045 ms | 9 MB + 200 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #8 | 37.727 ms | 11 MB + 360 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #9 | 37.739 ms | 11 MB + 360 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #10 | 36.758 ms | 11 MB + 92 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #11 | 38.96 ms | 11 MB + 708 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #12 | 34.977 ms | 10 MB + 588 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #13 | 1.076 ms | 9 MB + 200 KB | Accepted | Score: 0 | 显示更多 |