Topic Links:
First one
Time limit:4000/2000 MS (java/others)
Memory limit:131072/131072 K (java/others)
problem DescriptionSoda have an integer arraya1,a2,... ,an . LetS(i,J) Be the sum of Ai,ai+< Span id= "mathjax-span-36" class= "mn" >1 , Aj . Now soda wants to know the value below: ∑I=1N∑J=IN(⌊ Log2 s ( I,j ) ⌋ +1) X (i +j)
Note:in This problem, you can consider log20 as 0.
InputThere is multiple test cases. The first line of input contains an integerT, indicating the number of test cases. For each test case:
The first line contains an integerN (1≤n≤5) The number of integers in the array.
The next line containsNIntegersa1,a2,... ,an (0≤ai≤5).
OutputFor each test case, output the value.
Sample Input121 1
Sample Output12
Test Instructions:I beg for this sum.
Ideas:Still have to use the ruler, I find two end points, tle, it seems that the constant card is very tight ah ah;
AC Code:
/*5358 1638MS 3120K 1119 B g++ 2014300227*/#include<bits/stdc++.h>using namespacestd;Const intn=1e5+4; typedefLong Longll;intN;ll A[n],sum[n];intMain () {intT; scanf ("%d",&t); while(t--) {scanf ("%d",&N); for(intI=1; i<=n;i++) {scanf ("%lld",&A[i]); } sum[0]=0; A[n+1]=0; for(intI=1; i<=n+1; i++) {Sum[i]=sum[i-1]+A[i]; } ll ans=0, num=0; ll L=0, r=1, Len; for(intI=0; i<= -; i++) {num=0; intL=1, r=1; for(intj=1; j<=n;j++) {L=Max (j,l); while(l<=n&&sum[l]-sum[j-1]<L) l++; R=Max (r,l); while(r<=n&&sum[r]-sum[j-1]<=r&&sum[r]-sum[j-1]>=L) r++; Len=r-l; Num+=len* (LL) j+len* (l+r-1)/2; } L=r+1; R=2*l-1; Ans+=num* (LL) (i+1); } printf ("%lld\n", ans); } return 0;}
hdu-5358 first one (ruler)