# 「ZJOI2014」力

## Solution:

$E_k=\sum_{i=1}^{k-1} {q_i \over (k-i)^2} -\sum_{i=k+1} ^ n {q_i \over (i-k)^2}$

$E_k=\sum_{i=1}^{k-1} q_i C_{k-i} -\sum_{i=k+1} ^ n q_i C_{i-k}$

$E_k=\sum_{i=1}^{k-1} q_i C_{k-i} -\sum_{i=k+1} ^ n p_{n-i+1} C_{i-k}$

## Code：

#include<bits/stdc++.h>
#define Pi acos(-1.0)
using namespace std;
const int N=4e5+11;
int n,m,k,len=1,tim,p[N];
struct Complex{double x,y;}a[N],b[N],c[N];
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};}
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
void FFT(Complex *v,int flag){
for(int i=0;i<len;i++)
if(i<p[i]) swap(v[i],v[p[i]]);
for(int l=2;l<=len;l<<=1){
Complex wn=(Complex){cos(flag*2*Pi/l),sin(flag*2*Pi/l)};
for(int st=0;st<len;st+=l){
Complex w=(Complex){1,0};
for(int u=st;u<st+(l>>1);u++,w=w*wn){
Complex x=v[u],y=w*v[u+(l>>1)];
v[u]=x+y;v[u+(l>>1)]=x-y;
}
}
}
}
signed main(){
for(int i=1;i<n;i++) scanf("%lf",&a[i].x);
for(int i=1;i<n;i++) b[i].x=a[n-i].x;
for(int i=1;i<n;i++) c[i].x=(double)1.0/(double)i/(double)i;
while(len<=max(n,m)*2) len=len<<1,++tim;
for(int i=0;i<len;i++)
p[i]=(p[i>>1]>>1)|((i&1)<<(tim-1));
FFT(a,1);FFT(b,1);FFT(c,1);
for(int i=0;i<len;i++) a[i]=a[i]*c[i],b[i]=b[i]*c[i];
FFT(a,-1);FFT(b,-1);
for(int i=0;i<len;i++) a[i].x=a[i].x/len,b[i].x=b[i].x/len;
for(int i=1;i<n;i++) printf("%lf\n",a[i].x-b[n-i].x);
return 0;
}


posted @ 2020-01-29 11:39  DQY_dqy  阅读(114)  评论(0编辑  收藏  举报