题意:
给出n个数 qi q i ,F和E的定义如下:
Fj=∑i<jqiqj(i−j)2−∑i>jqiqj(i−j)2 F j = ∑ i < j q i q j ( i − j ) 2 − ∑ i > j q i q j ( i − j ) 2
求 Ei(n≤1e5,q≤1e9) E i ( n ≤ 1 e 5 , q ≤ 1 e 9 )
Solution:
化简式子: Ej=∑i<jqi(i−j)2−∑i>jqi(i−j)2 E j = ∑ i < j q i ( i − j ) 2 − ∑ i > j q i ( i − j ) 2
设 fi=qi,gi=1i2 f i = q i , g i = 1 i 2 ,这两块分别来求:
令 g0=0 g 0 = 0
∑i<jqi(i−j)2=∑i=0jqi∗gi−j=∑i=0jqi∗gj−i ∑ i < j q i ( i − j ) 2 = ∑ i = 0 j q i ∗ g i − j = ∑ i = 0 j q i ∗ g j − i
这一块显然可以FFT
∑i>jqi(i−j)2=∑i=jnqi∗gi−j=∑i=jnqi∗gj−i ∑ i > j q i ( i − j ) 2 = ∑ i = j n q i ∗ g i − j = ∑ i = j n q i ∗ g j − i
唉?好像不行?
注意到这个公式是从j到n,那么我们可以尝试一下翻转q和g数组:
∑i=0n−jqn−i∗gi−j ∑ i = 0 n − j q n − i ∗ g i − j
发现可以用FFT了诶
然后这道题就做完了QwQ
代码:
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
const double pi=acos(-1);
struct complex{
double x,y;
complex(double _x=0.0,double _y=0.0)
{
x=_x,y=_y;
}
complex operator +(const complex &b)const
{
return complex(x+b.x,y+b.y);
}
complex operator -(const complex &b)const
{
return complex(x-b.x,y-b.y);
}
complex operator *(const complex &b)const
{
return complex(x*b.x-y*b.y,x*b.y+y*b.x);
}
}x1[300010],x2[300010],x3[300010];
void change(complex y[],int len)
{
int i,j,k;
for (i=1,j=len/2;i<len-1;i++)
{
if (i<j) swap(y[i],y[j]);
k=len/2;
while (j>=k) j-=k,k>>=1;
if (j<k) j+=k;
}
}
void fft(complex y[],int len,int ifi)
{
change(y,len);
for (int h=2;h<=len;h*=2)
{
complex wn(cos(ifi*2*pi/h),sin(ifi*2*pi/h));
for (int j=0;j<len;j+=h)
{
complex w(1,0);
for (int k=j;k<j+h/2;k++)
{
complex u=y[k];
complex t=y[k+h/2]*w;
y[k]=u+t;y[k+h/2]=u-t;
w=w*wn;
}
}
}
if (ifi==-1) for (int i=0;i<len;i++) y[i].x/=len;
}
int n;
double a[100010],b[100010];
double ans[100010];
int main()
{
scanf("%d",&n);
for (int i=0;i<n;i++) scanf("%lf",&a[i]),b[n-i-1]=a[i];
int len=1;
while (len<2*n) len<<=1;
for (int i=0;i<n;i++) x1[i]=complex(a[i],0),x3[i]=complex(b[i],0);
for (int i=1;i<n;i++) x2[i]=complex((double)1.0/i/i,0);
fft(x1,len,1);fft(x2,len,1);fft(x3,len,1);
for (int i=0;i<len;i++) x1[i]=x1[i]*x2[i],x3[i]=x3[i]*x2[i];
fft(x1,len,-1);fft(x3,len,-1);
for (int i=0;i<n;i++) ans[i]+=x1[i].x;
for (int i=0;i<n;i++) ans[i]-=x3[n-i-1].x;
for (int i=0;i<n;i++) printf("%.3f\n",ans[i]);
}