# 洛谷 P3338 [ZJOI2014]力 fft

f[i]=sum(g[j]*h[i-j])

// luogu-judger-enable-o2
#include <iostream>
#include <cstdio>
#include <cmath>

const int maxn=3e5+7;
const double pi=acos(-1);

using namespace std;

struct rec{
double x,y;
};

rec operator + (rec a,rec b)
{
return (rec){a.x+b.x,a.y+b.y};
}

rec operator - (rec a,rec b)
{
return (rec){a.x-b.x,a.y-b.y};
}

rec operator * (rec a,rec b)
{
return (rec){a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x};
}

int n,m;
rec a[maxn],b[maxn],c[maxn];
int r[maxn],l,p;

void fft(rec *a,int f)
{
for (int i=0;i<l;i++)
{
if (r[i]>i) swap(a[i],a[r[i]]);
}
for (int i=2;i<=l;i*=2)
{
rec wn=(rec){cos(2*pi/i),f*sin(2*pi/i)};
for (int j=0;j<l;j+=i)
{
rec w=(rec){1,0};
for (int k=0;k<i/2;k++)
{
rec u=a[j+k],v=w*a[j+k+i/2];
a[j+k]=u+v;
a[j+k+i/2]=u-v;
w=w*wn;
}
}
}
}
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%lf",&a[i].x);
b[n-i+1].x=a[i].x;
c[i].x=(double)1/i/i;
}
l=1;p=0;
while (l<=(n*2)) l*=2,p++;
for (int i=0;i<l;i++) r[i]=((r[i>>1]>>1)|((i&1)<<(p-1)));
fft(a,1); fft(b,1); fft(c,1);
for (int i=0;i<l;i++)
{
a[i]=a[i]*c[i];
b[i]=b[i]*c[i];
}
fft(a,-1); fft(b,-1);
for (int i=0;i<l;i++)
{
a[i].x=a[i].x/l;
b[i].x=b[i].x/l;
}
for (int i=1;i<=n;i++) printf("%.3lf\n",a[i].x-b[n-i+1].x);
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120