Advertisement
tuki2501

fcb028_bits.cpp

Nov 9th, 2021
969
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve() {
  5.   int n; cin >> n;
  6.   vector<int> a(n);
  7.   for (auto &i : a) {
  8.     cin >> i;
  9.   }
  10.   long long ans = 0;
  11.   vector<array<int,2>> cnt(31);
  12.   for (auto &i : a) {
  13.     for (int j = 0; j < 31; j++) {
  14.       int t = (i >> j) & 1;
  15.       ans += (1ll << j) * cnt[j][!t];
  16.       cnt[j][t]++;
  17.     }
  18.   }
  19.   cout << ans << '\n';
  20. }
  21.  
  22. int main() {
  23.   cin.tie(0)->sync_with_stdio(0);
  24.   int T; cin >> T;
  25.   while (T--) solve();
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement