标签:
1 2 1 1
12
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define prt(k) cout<<#k" = "<<k<<" " const int N = 100233; int a[N]; int n; int main() { int re; read(re); while (re--) { read(n); ll ans = 0; for (ll i=1;i<=n;i++) { read(a[i]); ans += i * (n-i+1) + (n-i+1)*(n+i)/2; } for (int k=1;k<40;k++) { ll lim = 1LL<<k; ll s = 0; for (ll i=1, j=1; i<=n; i++) { while (j<=n && s<lim) s+=a[j++]; j--; if (s >= lim) { ans += i * ll(n - j + 1) + ll(n + j) * ll(n - j + 1)/2; j++; } else break; s -= a[i]; } } printf("%I64d\n", ans); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/oilover/article/details/47324029