#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
const double PI = 3.14159265358979323846;
#define int long long
const int N = 300005;
using namespace std;
struct Complex {
double a, b;
Complex operator+(Complex o) const { return { a + o.a, b + o.b }; }
Complex operator-(Complex o) const { return { a - o.a, b - o.b }; }
Complex operator*(Complex o) const { return { a * o.a - b * o.b, a * o.b + b * o.a }; }
Complex operator/(double o) const { return { a / o, b / o }; }
Complex operator~() const { return { a, -b }; }
Complex operator-() const { return { -a, -b }; }
};
Complex f[N], g[N], tmp[N];
int n, lgn, m[2], r[N];
void change(Complex x[]) {
for (int i = 0; i < n; i++) {
r[i] = r[i >> 1] >> 1;
if (i & 1)
r[i] |= (n >> 1);
}
for (int i = 0; i < n; i++)
if (i < r[i])
swap(x[i], x[r[i]]);
}
void fft(Complex t[], int on) {
change(t);
for (int h = 2; h <= n; h <<= 1) {
Complex wn = { cos(2 * PI / h), sin(on * 2 * PI / h) };
for (int j = 0; j < n; j += h) {
Complex w = { 1, 0 };
for (int k = j; k < j + h / 2; k++) {
Complex u = t[k], tmp = w * t[k + h / 2];
t[k] = u + tmp, t[k + h / 2] = u - tmp;
w = w * wn;
}
}
}
}
main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> m[0] >> m[1];
m[0]++, m[1]++;
for (int i = 0, x; i < m[0]; i++) cin >> x, f[i].a = x;
for (int i = 0, x; i < m[1]; i++) cin >> x, f[i].b = x;
lgn = __lg(m[0] + m[1] - 2) + 1;
n = 1 << lgn;
fft(f, 1);
for (int i = 0; i < n; i++) f[i] = f[i] * f[i];
fft(f, -1);
for (int i = 0; i < m[0] + m[1] - 1; i++) printf("%lld ", (int)round(f[i].b / (2 * n)));
putchar(10);
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Subtask #1 Testcase #1 | 53.53 us | 76 KB | Accepted | Score: 100 | 显示更多 |
Subtask #1 Testcase #2 | 57.554 ms | 7 MB + 508 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #3 | 26.705 ms | 3 MB + 360 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #4 | 26.676 ms | 3 MB + 348 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #5 | 44.76 us | 76 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #6 | 43.63 us | 76 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #7 | 42.5 us | 76 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #8 | 50.916 ms | 7 MB + 240 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #9 | 50.9 ms | 7 MB + 240 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #10 | 44.363 ms | 6 MB + 996 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #11 | 57.587 ms | 7 MB + 588 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #12 | 58.453 ms | 6 MB + 468 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #13 | 43 us | 76 KB | Accepted | Score: 0 | 显示更多 |