#include <bits/stdc++.h>
#define file(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
#define Enter putchar('\n')
#define quad putchar(' ')
#define N 3000005
namespace IO {
template <class T>
inline void read(T &a);
template <class T, class ...rest>
inline void read(T &a, rest &...x);
template <class T>
inline void write(T x);
}
struct cp {
double x, y;
cp (double xx = 0, double yy = 0) {x = xx; y = yy;};
friend cp operator +(cp p, cp q) {return cp(p.x + q.x, p.y + q.y);}
friend cp operator -(cp p, cp q) {return cp(p.x - q.x, p.y - q.y);}
friend cp operator *(cp p, cp q) {return cp(p.x * q.x - p.y * q.y, p.y * q.x + p.x * q.y);}
}a[N], b[N];
const double pi = 3.1415926535;
int n1, n2, n, rev[N], c[N];
inline void FFT(cp *a, int n, int inv) {
int bit = 0;
while ((1 << bit) < n) bit++;
for (int i = 1; i < n; ++i) {
rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (bit - 1));
if (i < rev[i])
std::swap(a[rev[i]], a[i]);
}
for (int mid = 1; mid < n; mid <<= 1) {
cp temp(cos(pi / mid), inv * sin(pi / mid));
for (int i = 0; i < n; i += mid * 2) {
cp omega(1,0);
for (int j = 0; j < mid; ++j, omega = omega * temp) {
cp x = a[i + j], y = omega * a[i + j + mid];
a[i + j] = x + y;
a[i + j + mid] = x - y;
}
}
}
}
signed main(void) {
// file("P3803");
IO::read(n1, n2);
n = std::max(n1, n2);
for (int i = 0, num; i <= n1; ++i) IO::read(num), a[i].x = num;
for (int i = 0, num; i <= n2; ++i) IO::read(num), b[i].x = num;
n = n1 + n2;
for (int i = 0; i <= 30; ++i)
if ((1 << i) > n) {
n = (1 << i);
break;
}
FFT(a, n, 1); FFT(b, n, 1);
for (int i = 0; i < n; ++i) a[i] = a[i] * b[i];
FFT(a, n, -1);
for (int i = 0; i <= n1 + n2; ++i)
c[i] = (int)(a[i].x / n + 0.5);
for (int i = 0; i <= n1 + n2; ++i)
IO::write(c[i]), quad;
Enter;
}
namespace IO {
template <class T>
inline void read(T &a) {
T s = 0, t = 1;
char c = getchar();
while ((c < '0' || c > '9') && c != '-')
c = getchar();
if (c == '-')
c = getchar(), t = -1;
while (c >= '0' && c <= '9')
s = (s << 1) + (s << 3) + (c ^ 48), c = getchar();
a = s * t;
}
template <class T, class ...rest>
inline void read(T &a, rest &...x) {
read(a);
read(x...);
}
template <class T>
inline void write(T x) {
if (x == 0) putchar('0');
if (x < 0) putchar('-'), x = -x;
int top = 0, sta[55] = {0};
while (x)
sta[++top] = x % 10, x /= 10;
while (top)
putchar(sta[top] + '0'), top--;
return ;
}
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Subtask #1 Testcase #1 | 10.79 ms | 91 MB + 612 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #2 | 46.095 ms | 94 MB + 796 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #3 | 25.486 ms | 92 MB + 768 KB | Accepted | Score: 100 | 显示更多 |
Subtask #1 Testcase #4 | 25.365 ms | 92 MB + 756 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #5 | 10.51 ms | 91 MB + 612 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #6 | 10.257 ms | 91 MB + 612 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #7 | 10.263 ms | 91 MB + 612 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #8 | 44.773 ms | 94 MB + 392 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #9 | 44.214 ms | 94 MB + 392 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #10 | 42.929 ms | 93 MB + 1016 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #11 | 45.893 ms | 94 MB + 876 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #12 | 40.209 ms | 93 MB + 756 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #13 | 10.632 ms | 91 MB + 608 KB | Accepted | Score: 0 | 显示更多 |