# bzoj2194: 快速傅立叶之二

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
const double pi=M_PI;
const int maxn=270010;
using namespace std;
struct plex{
double r,i;
}tmp[maxn];

plex operator +(plex a,plex b){return (plex){a.r+b.r,a.i+b.i};}
plex operator -(plex a,plex b){return (plex){a.r-b.r,a.i-b.i};}
plex operator *(plex a,plex b){return (plex){a.r*b.r-a.i*b.i,a.r*b.i+a.i*b.r};}
int n,nn;

struct DFT{
plex a[maxn];
void fft(int bg,int step,int size,int op){
if (size==1) return;
fft(bg,step<<1,size>>1,op),fft(bg+step,step<<1,size>>1,op);
plex w=(plex){1,0},t=(plex){cos(2*pi/size),sin(op*2*pi/size)};
int p=bg,p0=bg,p1=bg+step;
for (int i=0;i<size/2;i++){
tmp[p]=a[p0]+w*a[p1];
tmp[p+size/2*step]=a[p0]-w*a[p1];
p+=step,p0+=step*2,p1+=step*2,w=w*t;
}
for (int i=bg;size;size--,i+=step) a[i]=tmp[i];
}
}a,b,c;

int main(){
scanf("%d",&n);
for (int i=0;i<n;i++) scanf("%lf%lf",&a.a[i].r,&b.a[n-i-1].r);
for (nn=1;nn<(n<<1);nn<<=1);
a.fft(0,1,nn,1),b.fft(0,1,nn,1);
for (int i=0;i<nn;i++) c.a[i]=a.a[i]*b.a[i];
c.fft(0,1,nn,-1);
for (int i=n-1;i<2*n-1;i++) printf("%d\n",(int)round(c.a[i].r/nn));
return 0;
}

posted @ 2015-07-16 11:02  orzpps  阅读(81)  评论(0编辑  收藏  举报