Advertisement
Guest User

oddbin

a guest
Jun 14th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. using namespace std;
  5. typedef unsigned long long ull;
  6.  
  7. int main()
  8. {
  9.     ios::sync_with_stdio(false);
  10.     int ntest;
  11.     cin >> ntest;
  12.     for (int test = 0; test < ntest; test++) {
  13.         int n;
  14.         cin >> n;
  15.         vector<ull> a(n);
  16.         vector<ull> b(1<<n);
  17.         vector<ull> c(n);
  18.         for (auto & x: a) {
  19.             cin >> x;
  20.         }
  21.         for (unsigned int i = 1; i < 1u<<n; i++) {
  22.             unsigned int j = i & (i-1);
  23.             if (j == 0) {
  24.                 b[i] = a[__builtin_ctz(i)];
  25.             }
  26.             else {
  27.                 b[i] = b[j] & b[i-j];
  28.             }
  29.             c[__builtin_popcount(i)-1] += 1ull<<__builtin_popcountll(b[i]);
  30.         }
  31.         ull ans = 0;
  32.         for (int i = 0; i < n; i++) {
  33.             if (i & 1) {
  34.                 ans -= c[i]<<i;
  35.             }
  36.             else {
  37.                 ans += c[i]<<i;
  38.             }
  39.         }
  40.         printf("%llu\n", ans);
  41.     }
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement