题意:
给你
n
n
n个数
q
i
q_i
qi,对于每个
j
j
j求出
F
j
F_j
Fj,
F
j
=
∑
i
=
1
j
−
1
q
i
(
i
−
j
)
2
−
∑
i
=
j
+
1
n
q
i
(
i
−
j
)
2
F_j=\sum_{i=1}^{j-1}\frac{q_i}{(i-j)^2}-\sum_{i=j+1}^{n}\frac{q_i}{(i-j)^2}
Fj=∑i=1j−1(i−j)2qi−∑i=j+1n(i−j)2qi
n
<
=
1
e
5
n<=1e5
n<=1e5
题解:
我们发现我们可以分成两部分,对于减号两边分别计算。我们设
f
(
i
)
=
q
i
,
g
(
i
)
=
1
i
2
f(i)=q_i,g(i)=\frac{1}{i^2}
f(i)=qi,g(i)=i21,每部分都可以看作一个卷积,前半部分可以看作
∑
i
=
1
j
−
1
f
(
i
)
∗
g
(
i
−
j
)
\sum_{i=1}^{j-1}f(i)*g(i-j)
∑i=1j−1f(i)∗g(i−j),后面部分可以看作
∑
i
=
j
+
1
n
f
(
i
)
∗
g
(
i
−
j
)
\sum_{i=j+1}^nf(i)*g(i-j)
∑i=j+1nf(i)∗g(i−j)。为了方便,我们构造一个
f
′
f'
f′,
f
′
f'
f′是
f
f
f数组翻转后的数组,这样就可以把第二个式子变成
∑
i
=
0
i
−
1
f
′
(
i
)
∗
g
(
i
−
j
)
\sum_{i=0}^{i-1}f'(i)*g(i-j)
∑i=0i−1f′(i)∗g(i−j)。然后就是FFT求两个卷积,再对应减一下。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
int n,l,rev[400010],m;
const double pi=acos(-1);
struct complex
{
double x,y;
complex(double xx=0,double yy=0)
{
x=xx;
y=yy;
}
};
complex operator + (complex a,complex b){return complex(a.x+b.x,a.y+b.y);}
complex operator - (complex a,complex b){return complex(a.x-b.x,a.y-b.y);}
complex operator * (complex a,complex b){return complex(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);}
complex f[400010],g[400010],ff[400010];
inline void fft(complex *a,int dft)
{
for(int i=0;i<n;++i)
{
if(i<rev[i])
swap(a[i],a[rev[i]]);
}
for(int i=1;i<n;i<<=1)
{
complex wn(cos(pi/i),dft*sin(pi/i));
for(int p=i<<1,j=0;j<n;j+=p)
{
complex w(1,0);
for(int k=0;k<i;++k)
{
complex x=a[j+k],y=w*a[i+j+k];
a[j+k]=x+y;
a[i+j+k]=x-y;
w=w*wn;
}
}
}
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%lf",&f[i].x);
g[i].x=1.0/(double)i/(double)i;
ff[n-i].x=f[i].x;
}
m=n*2;
for(n=1;n<=m;n<<=1)
++l;
for(int i=0;i<n;++i)
rev[i]=(rev[i>>1]>>1)|((i&1)<<(l-1));
fft(f,1);
fft(g,1);
fft(ff,1);
for(int i=0;i<n;++i)
{
f[i]=f[i]*g[i];
ff[i]=ff[i]*g[i];
}
fft(f,-1);
fft(ff,-1);
for(int i=1;i<=m/2;++i)
printf("%.10lf\n",(f[i].x-ff[(m/2)-i].x)/n);
return 0;
}