Given the number of Qi of n, the definition of FJ is as follows:
Make Ei=fi/qi, seek ei.
Exercises
Why take qi and divide qi ...
We found that i-j+j=i is a definite value, which is a convolution. Can be counted separately, the first half
Make a[i]=1/(I*i), B[i]=q[i], and their convolution c[i] is the value of the first half.
The second half we'll just flip the b over and do it again.
Be careful not to add useless and nonexistent items to a.
Code: Faster than the original Pascal 10s 233
1#include <cstdio>2 3#include <cstdlib>4 5#include <cmath>6 7#include <cstring>8 9#include <algorithm>Ten One#include <iostream> A -#include <vector> - the#include <map> - -#include <Set> - +#include <queue> - +#include <string> A at #defineINF 1000000000 - - #defineMAXN 500000+5 - - #defineMAXM 20000000+5 - in #defineEPS 1e-10 - to #definell Long Long + - #definePA pair<int,int> the * #defineFor0 (i,n) for (int i=0;i<= (n); i++) $ Panax Notoginseng #defineFor1 (i,n) for (int i=1;i<= (n); i++) - the #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + A #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) the + #defineMoD 1000000007 - $ using namespacestd; $ -InlineintRead () - the { - Wuyi intx=0, f=1;CharCh=GetChar (); the - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} Wu - while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} About $ returnx*F; - - } - structCP A { + Doublex, y; theCpoperator+ (CP b) {return(CP) {x+b.x,y+b.y};} -Cpoperator-(CP b) {return(CP) {x-b.x,y-b.y};} $Cpoperator* (CP b) {return(CP) {x*b.x-y*b.y,x*b.y+y*b.x};} the }; the DoubleD[MAXN],ANS[MAXN]; the //const double pi=3.1415926535898; the Const DoublePi=acos (-1.0); - CP A[MAXN],B[MAXN],C[MAXN],Y[MAXN]; in intN,NN,M,LEN,REV[MAXN]; the voidFFT (CP *x,intNintflag) the { AboutFor0 (i,n-1) y[rev[i]]=X[i]; theFor0 (i,n-1) x[i]=Y[i]; the for(intm=2; m<=n;m<<=1) the { +CP wn= (CP) {cos (2.0*pi/m*flag), Sin (2.0*pi/m*flag)}; - for(intI=0; i<n;i+=m) the {BayiCP w= (CP) {1,0};intMid=m>>1; theFor0 (j,mid-1) the { -CP u=x[i+j],v=x[i+j+mid]*W; -x[i+j]=u+v;x[i+j+mid]=u-v; thew=w*WN; the } the } the } - if(flag==-1) For0 (i,n-1) x[i].x/=N; the } the the intMain ()94 the { the theFreopen ("Input.txt","R", stdin);98 AboutFreopen ("output.txt","W", stdout); - 101nn=n=read ();102n=2*n-1; m=1;103 while(m<=n) m<<=1, len++;n=m;104For0 (i,nn-1) scanf ("%LF",&d[i]); theFor0 (i,n-1) a[i]= (CP) {D[i],0};106For0 (i,nn-1) b[i]=i? (CP) {1.0/((Double) i* (Double) i),0}:(CP) {0,0};107For2 (i,nn,n-1) b[i]= (CP) {0,0};108For0 (i,n-1)109 { the intx=i,y=0;111For1 (J,len) y<<=1,y|=x&1, x>>=1; therev[i]=y;113 } theFFT (A,n,1); FFT (B,n,1); theFor0 (i,n-1) c[i]=a[i]*B[i]; theFFT (c,n,-1);117For0 (i,nn-1) ans[i]=c[i].x;118For0 (i,nn-1) a[i]= (CP) {d[nn-1-I.],0};119For2 (i,nn,n-1) a[i]= (CP) {0,0}; -For0 (i,nn-1) b[i]=i? (CP) {1.0/((Double) i* (Double) i),0}:(CP) {0,0};121For2 (i,nn,n-1) b[i]= (CP) {0,0};122FFT (A,n,1); FFT (B,n,1);123For0 (i,n-1) c[i]=a[i]*B[i];124FFT (c,n,-1); theFor0 (i,nn-1) ans[i]-=c[nn-1-i].x;126For0 (i,nn-1) printf ("%.5f\n", Ans[i]);127 - return 0;129 the}View Code
BZOJ3527: [Zjoi2014] Force