Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double ld;
- typedef pair<int, int> pii;
- typedef pair<ll, ll> pll;
- typedef pair<ull, ull> puu;
- #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
- #define file_in freopen("input.txt", "r", stdin);
- #define all(x) (x).begin(), (x).end()
- #define sz(x) (int)x.size()
- #define fi first
- #define se second
- template<typename T> istream& operator>>(istream& in, vector<T> &v) { for (auto &el : v) in >> el; return in; }
- template<typename T> ostream& operator<<(ostream& out, vector<T> &v) { for (auto &el : v) out << el << " "; return out; }
- template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &v) { in >> v.first >> v.second; return in; }
- template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &v) { cout << v.first << " " << v.second; return out; }
- int main() {
- fast
- // file_in
- int n;
- cin >> n;
- n = (1 << n);
- vector<int> a(n);
- cin >> a;
- if (n == 2) {
- cout << 2 << '\n';
- return 0;
- }
- int mask = 0, cnt = 0;
- ll res = 0;
- unordered_map<int, vector<int>> ht;
- for (int i = 0; i < n; ++i) {
- a[i] = min(a[i], n - a[i] - 1);
- if ((mask >> a[i]) & 1) ++cnt;
- mask ^= 1 << a[i];
- if (ht[mask].empty()) {
- ht[mask].resize(2);
- }
- res += ht[mask][cnt % 2];
- ht[mask][cnt % 2]++;
- }
- cout << 1ll * n * (n + 1) / 2 - res - ht[0][0] << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement