Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <vector>
- using namespace std;
- typedef unsigned long long ull;
- int main()
- {
- ios::sync_with_stdio(false);
- int ntest;
- cin >> ntest;
- for (int test = 0; test < ntest; test++) {
- int n;
- cin >> n;
- vector<ull> a(n);
- vector<ull> b(1<<n);
- vector<ull> c(n);
- for (auto & x: a) {
- cin >> x;
- }
- for (unsigned int i = 1; i < 1u<<n; i++) {
- unsigned int j = i & (i-1);
- if (j == 0) {
- b[i] = a[__builtin_ctz(i)];
- }
- else {
- b[i] = b[j] & b[i-j];
- }
- c[__builtin_popcount(i)-1] += 1ull<<__builtin_popcountll(b[i]);
- }
- ull ans = 0;
- for (int i = 0; i < n; i++) {
- if (i & 1) {
- ans -= c[i]<<i;
- }
- else {
- ans += c[i]<<i;
- }
- }
- printf("%llu\n", ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement