#include<cstdio>
#include<algorithm>
#include<ctype.h>
#include<string.h>
#include<math.h>
using namespace std;
#define ll long long
static char buf[1<<19], *s=buf;
inline void read(int &x) {
while(isspace(*s)) ++s;
x=*s++^'0';
while(isdigit(*s)) x=x*10+(*s++^'0');
}
char obuf[1<<20], *ooh=obuf;
inline void print(int x) {
static int buf[30], cnt;
if (x==0) *ooh++='0';
else {
for (cnt=0; x; x/=10) buf[++cnt]=x%10+48;
while(cnt) *ooh++=buf[cnt--];
}
}
const double Pi = acos(-1);
const int N = 1<<18;
int n, m;
struct cp{
double a, b;
inline void operator +=(const cp &rhs){ a+=rhs.a, b+=rhs.b;}
inline cp operator +(const cp &rhs)const{ return (cp){a+rhs.a, b+rhs.b};}
inline cp operator -(const cp &rhs)const{ return (cp){a-rhs.a, b-rhs.b};}
inline cp operator *(const cp &rhs)const{ return (cp){a*rhs.a-b*rhs.b, a*rhs.b+b*rhs.a};}
inline cp operator *(const double rhs)const{ return (cp){a*rhs, b*rhs};}
inline cp operator ~()const{ return (cp){a, -b};}
} f[N], w[N];
inline int Get(int x){ int n=1; while(n<=x) n<<=1; return n;}
inline void DFT_(cp *f, int n){
for(register int i=0, j=0; i<n; ++i){
if(i>j) swap(f[i], f[j]);
for(register int k=n>>1; (j^=k)<k; k>>=1);
}
for(register int i=1; i<n; i<<=1) for(register int j=0; j<n; j+=i<<1)
for(register int k=j; k<j+i; ++k){
cp t=w[i+k-j]*f[k+i];
f[k+i]=f[k]-t, f[k]+=t;
}
}
inline void IDFT(cp *f, int n){
if(n==1) return;
reverse(f+1, f+n), n>>=1;
static cp a[N/2];
for(register int i=0; i<n; ++i)
a[i]=(f[i]+f[i+n])*.5 + (f[i]-f[i+n])*(cp){0, .5}*w[n+i];
DFT_(a, n);
double k=1./n;
for(register int i=0; i<n; ++i) f[i<<1]=(cp){a[i].a*k, 0}, f[i<<1|1]=(cp){a[i].b*k, 0};
}
int main() {
fread(s, 1, 1<<19, stdin);
read(n), read(m), ++n, ++m;
for(int i=0, x; i<n; ++i) read(x), f[i].a=x;
for(int i=0, x; i<m; ++i) read(x), f[i].b=x;
int l=Get(n+m-2);
for(int i=1; i<l; i<<=1){
w[i]=(cp){1, 0};
for(int j=1; j<i; ++j)
w[i+j]=((j&31)==1?(cp){cos(Pi*j/i), sin(Pi*j/i)}:w[i+j-1]*w[i+1]);
}
DFT_(f, l);
for(int i=0; i<=l>>1; ++i){
int j=(l-i)&(l-1);
cp x=f[i]*f[i], y=f[j]*f[j];
f[i]=(x-~y)*(cp){0, -.25}, f[j]=(y-~x)*(cp){0, -.25};
}
IDFT(f, l);
for(int i=0; i<n+m-1; ++i) print((int)(f[i].a+0.5)), *ooh++=' ';
return fwrite(obuf, 1, ooh - obuf, stdout), 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Subtask #1 Testcase #1 | 8.23 us | 32 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #2 | 21.075 ms | 12 MB + 872 KB | Accepted | Score: 100 | 显示更多 |
Subtask #1 Testcase #3 | 7.916 ms | 5 MB + 784 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #4 | 7.907 ms | 5 MB + 764 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #5 | 8.86 us | 32 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #6 | 7.95 us | 32 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #7 | 8.15 us | 32 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #8 | 19.907 ms | 12 MB + 496 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #9 | 19.932 ms | 12 MB + 496 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #10 | 18.768 ms | 12 MB + 60 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #11 | 21.43 ms | 13 MB + 8 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #12 | 16.582 ms | 11 MB + 160 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #13 | 7.17 us | 28 KB | Accepted | Score: 0 | 显示更多 |