It is necessary to spit out the English level of this question. FFT strong, there is no difficulty.
1#include <iostream>2#include <cstring>3#include <cstdio>4#include <cmath>5 using namespacestd;6 Const Long DoublePi=acos (-1.0);7 Const intmaxn=300010;8 structcomplex{9 Long Doubler,i;TenComplexLong Doubler_=0.0,Long Doublei_=0.0){ OneR=r_;i=I_; A } -Complexoperator+ (Complex &a) { - returnComplex (r+a.r,i+A.I); the } -Complexoperator-(Complex &a) { - returnComplex (r-a.r,i-A.I); - } +Complexoperator* (Complex &a) { - returnComplex (r*a.r-i*a.i,r*a.i+i*A.R); + } A }A[MAXN],B[MAXN],C[MAXN],D[MAXN]; at - voidRader (Complex *a,intLen) { - for(intI=1,j=len>>1; i<len-1; i++){ - if(i<j) Swap (A[i],a[j]); - intK=len>>1; - while(j>=k) { inj-=K; -k>>=1; to } +j+=K; - } the } * $ voidFFT (Complex *a,intLenintOn ) {Panax Notoginseng rader (a,len); - for(intH=2; h<=len;h<<=1){ theComplex WN (cos (-on*pi*2/h), sin (-on*pi*2/h)); + for(intj=0; j<len;j+=h) { AComplex W (1.0,0); the for(intk=j;k<j+ (h>>1); k++){ +Complex x=A[k]; -Complex y=a[k+ (h>>1)]*W; $a[k]=x+y; $a[k+ (h>>1)]=x-y; -w=w*WN; - } the } - }Wuyi if(on==-1) the for(intI=0; i<len;i++) -A[i].r/=Len; Wu } - About intD[MAXN]; $ intMain () { - #ifndef Online_judge - //freopen (); - //freopen (); A #endif + intT,n,len; the Long LongTot,zero; -scanf"%d",&T); $ while(t--){ thescanf"%d",&n); thetot=zero=0; the for(intI=1; i<=n;i++){ thescanf"%d",&d[i]); - if(d[i]==0){ intot+=1; thezero+=tot* (tot+1) >>1; the } About Elsetot=0; thed[i]+=d[i-1]; the } thelen=1; + while(len<=2*d[n]) len<<=1; -memset (A,0,sizeof(A)); thememset (B,0,sizeof(B));Bayimemset (C,0,sizeof(C)); thememset (D,0,sizeof(D)); the for(intI=0; i<=n;i++){ -a[d[i]].r+=1.0; -b[d[n]-d[i]].r+=i; thec[d[i]].r+=i; thed[d[n]-d[i]].r+=1.0; the } theFFT (A,len,1); FFT (B,len,1); - for(intI=0; i<len;i++) thea[i]=a[i]*B[i]; theFFT (a,len,-1); theFFT (C,len,1); FFT (D,len,1);94 for(intI=0; i<len;i++) thec[i]=c[i]*D[i]; theFFT (c,len,-1); theprintf"%lld\n", zero);98 for(inti=d[n]-1; i>=0; i--) Aboutprintf"%lld\n",(Long Long) (a[i].r-c[i].r+0.5)); - }101 return 0;102}
Anyway, it's past. Amount
FFT (Fast Fourier transform): HDU 5307 He is Flying