题目:BZOJ3527、洛谷P3338。
题目大意:
(F_j=sumlimits_{i<j}frac{q_i q_j}{(i−j)^2}−sumlimits_{i>j}frac{q_i q_j}{(i−j)^2})
令(E_i=frac{F_i} {q_i}),求(E_i)。
解题思路:
令(f[i]=q_i),(g[i]=frac 1 {i^2})((f[0]=0)),
则有(E_j=sumlimits_{i=0}^j f[i]g[j-i]-sumlimits_{i=j+1}^n f[i]g[j-i])
令(f'[i]=f[n-i+1]),则(sumlimits_{i=j+1}^n f[i]g[j-i]=sumlimits_{i=0}^{n-j}f'[i]g[n-j+i])。
两边均为卷积,FFT即可。
C++ Code:
#include<bits/stdc++.h> const int NN=262144; struct cpx{ double x,y; inline cpx operator +(const cpx&rhs)const{return(cpx){x+rhs.x,y+rhs.y};} inline cpx operator -(const cpx&rhs)const{return(cpx){x-rhs.x,y-rhs.y};} inline cpx operator *(const cpx&rhs)const{return(cpx){x*rhs.x-y*rhs.y,x*rhs.y+y*rhs.x};} }p[NN],q[NN],S[NN],a[NN],b[NN],SS[NN]; int n,rev[NN],N,l; void fft(cpx*a,int f){ for(int i=1;i<N;++i) if(i<rev[i])std::swap(a[i],a[rev[i]]); for(int i=1;i<N;i<<=1){ cpx wi{cos(M_PI/i),f*sin(M_PI/i)}; for(int j=0;j<N;j+=i<<1){ cpx w{1,0}; for(int k=0;k<i;++k){ cpx x=a[j+k],y=w*a[j+k+i]; a[j+k]=x+y,a[j+k+i]=x-y; w=w*wi; } } } if(!~f) for(int i=0;i<N;++i)a[i].x/=N,a[i].y/=N; } void mul(cpx*a,cpx*b,cpx*c){ fft(a,1),fft(b,1); for(int i=0;i<N;++i)c[i]=a[i]*b[i]; fft(c,-1); } int main(){ scanf("%d",&n); rev[0]=0; N=1,l=0; for(;N<n<<1;N<<=1)++l; for(int i=1;i<N;++i)rev[i]=(rev[i>>1]>>1)|((i&1)<<(l-1)); for(int i=1;i<=n;++i){ scanf("%lf",&q[i].x); SS[i].x=S[i].x=1./i/i; p[i]=q[i]; } std::reverse(p+1,p+n+1); mul(q,S,a),mul(p,SS,b); for(int i=1;i<=n;++i) printf("%.9f ",a[i].x-b[n-i+1].x); return 0; }