#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cmath>
namespace fastIO {
const int SZ = 1 << 25;
char ibuf[SZ], *p0 = ibuf, *p1 = ibuf;
inline char getchar(void) { return p0 == p1 && (p1 = (p0 = ibuf) + fread(ibuf, 1, SZ, stdin), p0 == p1) ? EOF : *p0++; }
char char_read; void read(auto &val) {
val = 0; do char_read = getchar(); while(!isdigit(char_read));
do val = val * 10 + char_read - '0'; while(isdigit(char_read = getchar()));
}
char obuf[SZ], *p = obuf;
inline void putchar(char char_write) { *p++ = char_write; }
void write(auto val) { if(val >= 10) write(val / 10); putchar(val % 10 + '0'); }
inline void write(auto a[], int sz) { for(int i = 0; i < sz; ++i) write(a[i]), putchar(' '); putchar('\n'); }
void output(void) { fwrite(obuf, p - obuf, 1, stdout);}
};
const int N = 1 << 21;
const double PI = acos(-1);
struct CMPLX {
double real, imag;
CMPLX operator + (CMPLX z) const { return (CMPLX){ real + z.real, imag + z.imag}; }
CMPLX operator - (CMPLX z) const { return (CMPLX){ real - z.real, imag - z.imag}; }
CMPLX operator * (CMPLX z) const { return (CMPLX){ real * z.real - imag * z.imag, real * z.imag + imag * z.real}; }
};
CMPLX conj(CMPLX z) { return (CMPLX){ z.real, -z.imag }; }
CMPLX fft_sup[N];
void fft(auto a[], int n, CMPLX w) {
auto fft_a = fft_sup, j = a, _j = a; int i, k, _k; auto _w = w;
for(i = 1; i < n; i <<= 1, w = w * w, std :: swap(a, fft_a))
for(k = 0, j = a, _j = a + (n >> 1), _w = (CMPLX){ 1, 0 }; k != n; k += i, _w = _w * w)
for(_k = k, k += i; _k != k; ++j, ++_j, ++_k)
fft_a[_k] = *j + *_j,
fft_a[_k + i] = (*j - *_j) * _w;
if(fft_a != fft_sup) std :: copy(a, a + n, fft_a);
}
void fft_2for1(auto a[], auto b[], int n) {
for(int i = 0; i < n; ++i) a[i].imag = b[i].real;
fft(a, n, (CMPLX){ cos(PI / n * 2), +sin(PI / n * 2) });
b->real = a->real, b->imag = -a->imag;
for(auto i = a + 1, j = b + n - 1; i != a + n; ++i, --j)
j->real = i->real, j->imag = -i->imag;
double t; for(auto i = a, j = b; i != a + n; ++i, ++j)
i->real = (i->real + j->real) * 0.5,
i->imag = (i->imag + j->imag) * 0.5,
t = j->real, j->real = i->imag - j->imag,
j->imag = t - i->real;
}
inline void poly_mul(auto a[], auto b[], int n) {
fft_2for1(a, b, n);
for(int i = 0; i < n; ++i) a[i] = a[i] * b[i];
fft(a, n, (CMPLX){ cos(PI / n * 2), -sin(PI / n * 2) });
double inv_n = 1.0 / n; for(int i = 0; i < n; ++i) a[i].real = a[i].real * inv_n;
}
int n, n_a, n_b;
CMPLX a[N], b[N];
int ans[N];
int main(void) {
fastIO :: read(n_a), fastIO :: read(n_b); ++n_a, ++n_b; for(n = 1; n < n_a + n_b; n <<= 1);
for(int i = 0, t; i < n_a; ++i) fastIO :: read(t), a[i].real = t;
for(int i = 0, t; i < n_b; ++i) fastIO :: read(t), b[i].real = t;
poly_mul(a, b, n); n = n_a + n_b - 1;
for(int i = 0; i < n; ++i) ans[i] = a[i].real + 0.5;
fastIO :: write(ans, n), fastIO :: output();
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Subtask #1 Testcase #1 | 8.59 us | 36 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #2 | 29.01 ms | 16 MB + 12 KB | Accepted | Score: 100 | 显示更多 |
| Subtask #1 Testcase #3 | 10.569 ms | 7 MB + 156 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #4 | 10.716 ms | 7 MB + 136 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #5 | 8.62 us | 36 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #6 | 7.77 us | 36 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #7 | 8.68 us | 36 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #8 | 28.103 ms | 15 MB + 300 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #9 | 28.152 ms | 15 MB + 300 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #10 | 27.295 ms | 14 MB + 588 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #11 | 29.244 ms | 16 MB + 176 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #12 | 25.898 ms | 13 MB + 956 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #13 | 8.5 us | 36 KB | Accepted | Score: 0 | 显示更多 |