1 //用C++交会超时,用G++ 2 #include <cstdio> 3 #include <iostream> 4 using namespace std; 5 #define ll __int64 6 const int maxn=100005; 7 ll l[35],r[35],sum[maxn]; 8 int main() 9 { 10 l[0]=0;r[0]=1; 11 for(int i=1;i<34;i++) 12 { 13 l[i]=(1ll<<i); 14 r[i]=((1ll<<(i+1))-1); 15 } 16 int t; 17 scanf("%d",&t); 18 while(t--) 19 { 20 int n,x; 21 scanf("%d",&n); 22 for(int i=1;i<=n;i++) 23 { 24 scanf("%d",&x); 25 sum[i]=sum[i-1]+x; 26 } 27 ll ans=0; 28 for(int i=1;i<35;i++) 29 { 30 if(sum[n]<l[i-1]) 31 break; 32 ll a=1,b=0,num=0; 33 for(int j=1;j<=n;j++) 34 { 35 a=(a>j ? a : j); 36 while(a<=n&&sum[a]-sum[j-1]<l[i-1]) 37 a++; 38 b=(b>a-1 ? b : a-1); 39 while(b+1<=n&&sum[b+1]-sum[j-1]<=r[i-1]) 40 b++; 41 if(b>=a) 42 num+=(b-a+1)*j+(a+b)*(b-a+1)/2; 43 } 44 ans+=num*i; 45 } 46 printf("%I64d\n",ans); 47 } 48 return 0; 49 }