Problem Description
JRY wants to drag racing along a long road. There are n sections on the road, the i -th section has a non-negative integer length si .
JRY will choose some continuous sections to race (at an unbelievable speed), so there are totally n(n+1)2 different ways for him to ride.
If JRY rides across from the i -th section to the j -th section, he would gain j?i+1 pleasure. Now JRY wants to know, if he tries all the ways whose length is s ,
what's the total pleasure he can get. Please be aware that in the problem, the length of one section could be zero, which means that the length is so trivial that we can regard it as 0
Input
The first line of the input is a single integer T (T=5) , indicating the number of testcases.
For each testcase, the first line contains one integer n . The second line contains n non-negative integers,
which mean the length of every section. If we denote the total length of all the sections as s , we can guarantee that 0≤s≤50000 and 1≤n≤100000 .
Output
For each testcase, print s+1 lines. The single number in the i -th line indicates the total pleasure JRY can get if he races all the ways of length i?1 .
Sample Input
2 3 1 2 3 4 0 1 2 3
Sample Output
0 1 1 3 0 2 3 1 3 1 6 0 2 7
1 #include<cmath> 2 #include<queue> 3 #include<cstdio> 4 #include<cstring> 5 #include<algorithm> 6 using namespace std; 7 const int DLT=50000; 8 const long double PI=acos(-1.0); 9 struct cp{ 10 long double x,y; 11 cp(){} 12 cp(long double a,long double b){x=a;y=b;} 13 cp friend operator + (cp a,cp b){return cp(a.x+b.x,a.y+b.y);} 14 cp friend operator - (cp a,cp b){return cp(a.x-b.x,a.y-b.y);} 15 cp friend operator * (cp a,cp b){return cp(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);} 16 }A[200010],B[200010],C[200010],D[200010]; 17 int T; 18 int n,m; 19 int lim; 20 int len; 21 int s[200010]; 22 int pos[200010]; 23 int sum[200010]; 24 void init(void) 25 { 26 memset(A,0,sizeof(A)); 27 memset(B,0,sizeof(B)); 28 memset(C,0,sizeof(C)); 29 memset(D,0,sizeof(D)); 30 return ; 31 } 32 void FFT(cp *a,double flag) 33 { 34 for(int i=0;i<len;i++)if(i<pos[i])std::swap(a[i],a[pos[i]]); 35 for(int i=2;i<=len;i<<=1) 36 { 37 cp wn(cos(2.00*flag*PI/i),sin(2.00*flag*PI/i)); 38 for(int j=0;j<len;j+=i) 39 { 40 cp w(1,0),t; 41 for(int k=0;k<(i>>1);k++,w=w*wn) 42 { 43 t=a[j+k+(i>>1)]*w; 44 a[j+k+(i>>1)]=a[j+k]-t; 45 a[j+k]=a[j+k]+t; 46 } 47 } 48 } 49 return ; 50 } 51 void work(void) 52 { 53 init(); 54 long long a0(0); 55 int cnt(0); 56 scanf("%d",&n); 57 for(int i=1;i<=n;i++) 58 { 59 scanf("%d",&s[i]); 60 if(!s[i]) 61 { 62 cnt++; 63 a0+=1ll*cnt*(cnt+1)/2; 64 }else cnt=0; 65 sum[i]=sum[i-1]+s[i]; 66 } 67 printf("%lld ",a0); 68 while((1<<lim)<(DLT<<1))lim++;len=1<<lim; 69 for(int i=0;i<len;i++)pos[i]=(pos[i>>1]>>1)|((i&1)<<(lim-1)); 70 for(int i=1;i<=n;i++) 71 { 72 A[sum[i]].x+=i;B[DLT-sum[i-1]].x+=1; 73 C[sum[i]].x+=1;D[DLT-sum[i-1]].x+=i-1; 74 } 75 FFT(A,1),FFT(B,1),FFT(C,1),FFT(D,1); 76 for(int i=0;i<len;i++)A[i]=A[i]*B[i]-C[i]*D[i]; 77 FFT(A,-1); 78 for(int i=1;i<=sum[n];i++)printf("%I64d ",(long long)(A[i+DLT].x/len+0.2)); 79 return ; 80 } 81 int main() 82 { 83 scanf("%d",&T); 84 while(T --> 0)work(); 85 return 0; 86 }