3527: [Zjoi2014] Force

Source: Internet
Author: User

The main topic: give the number of QI, the definition of FJ

      

Make Ei=fi/qi, Seek Ei.

Set a[i]=q[i],b[i]=1/(i^2).

Set C[i]=sigma (A[j]*b[i-j]), D[i]=sigma (A[n-j-1]*b[i-j]).

Then the e[i]=c[i]-d[i of the request].

It is not difficult to find C[i] is already the standard convolution form, with the FFT can.

For D[i], make A ' [i]=a[n-i-1], then D[i]=sigma (A[j]*b[i-j]), so also use FFT.

Code

1#include <cstdio>2#include <iostream>3#include <cmath>4#include <cstring>5#include <algorithm>6 #defineMAXN 2621447 #definePi 3.141592653589793238468 using namespacestd;9 Charch;Ten intM,n; One BOOLOK; A Long DoubleANS[MAXN]; - DoubleQ[MAXN]; - voidReadint&x) {  the      for(ok=0, Ch=getchar ();! IsDigit (CH); Ch=getchar ())if(ch=='-') ok=1;  -      for(x=0; isdigit (ch); x=x*Ten+ch-'0', ch=GetChar ());  -     if(OK) x=-x; - }  + structcomp{ -     Long DoubleRea,ima; +     voidClear () {rea=ima=0;}  ACompoperator+(ConstComp &x) {return(comp) {rea+x.rea,ima+X.ima};}  atCompoperator-(ConstComp &x) {return(comp) {rea-x.rea,ima-X.ima};}  -Compoperator*(ConstComp &x) {return(comp) {rea*x.rea-ima*x.ima,rea*x.ima+ima*X.rea};}  - }a[maxn],b[maxn],c[maxn],tmp[maxn],w,wn;  - voidFFT (Comp *a,intStintSizintStepintop) {  -     if(siz==1)return;  -FFT (a,st,siz>>1,step<<1, op), FFT (a,st+step,siz>>1,step<<1, op);  in     intx=st,x1=st,x2=st+Step; -w= (comp) {1,0},wn= (comp) {cos (op*2*pi/siz), sin (op*2*pi/siz)};  to      for(intI=0;i< (siz>>1); i++,x+=step,x1+= (step<<1), x2+= (step<<1), w=w*WN) +tmp[x]=a[x1]+ (w*a[x2]), tmp[x+ (siz>>1) *step]=a[x1]-(w*a[x2]);  -      for(inti=st;siz;i+=step,siz--) a[i]=Tmp[i]; the }  * intMain () { $Read (m), n=1; Panax Notoginseng      while(n< (m<<1)) n<<=1;  -      for(intI=0; i<m;i++) scanf ("%LF",&Q[i]);  the        +      for(intI=0; i<n;i++) a[i].clear ();  A      for(intI=0; i<n;i++) b[i].clear ();  the      for(intI=0; i<m;i++) a[i].rea=Q[i]; +      for(intI=1; i<m;i++) b[i].rea=1.0/i/i; -FFT (A,0N1,1), FFT (b,0N1,1);  $      for(intI=0; i<n;i++) c[i]=a[i]*B[i]; $FFT (c,0N1,-1);  -      for(intI=0; i<m;i++) ans[i]=c[i].rea/N; -        the      for(intI=0; i<n;i++) a[i].clear ();  -      for(intI=0; i<n;i++) b[i].clear (); Wuyi      for(intI=0; i<m;i++) a[i].rea=q[m-i-1];  the      for(intI=1; i<m;i++) b[i].rea=1.0/i/i; -FFT (A,0N1,1), FFT (b,0N1,1);  Wu      for(intI=0; i<n;i++) c[i]=a[i]*B[i]; -FFT (c,0N1,-1);  About        $      for(intI=0; i<m;i++) printf ("%.9lf\n",(Double) (ans[i]-c[m-i-1].rea/N));  -     return 0;  -}

3527: [Zjoi2014] Force

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.