fork(3) download
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. using namespace std;
  4. const int N = 100000 + 10;
  5. int t, n, a[N];
  6. ll ans;
  7. int main() {
  8. scanf("%d", &t);
  9. while (t--) {
  10. ans = 0;
  11. scanf("%d", &n);
  12. for (int i = 0; i < n; ++i)
  13. scanf("%d", a + i);
  14. for (int k = 0; k <= 20; ++k) {
  15. int cnt = 0;
  16. for (int i = 0, v; i < n; ++i) {
  17. v = (a[i] >> k) & 1;
  18. if (v) {
  19. ++cnt;
  20. }
  21. else {
  22. ans += (ll)cnt * (cnt + 1) / 2 * (1 << k);
  23. cnt = 0;
  24. }
  25. }
  26. ans += (ll)cnt * (cnt + 1) / 2 * (1 << k);
  27. }
  28. printf("%lld\n", ans);
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 15624KB
stdin
Standard input is empty
stdout
Standard output is empty