Advertisement
MathQ_

Untitled

Jan 21st, 2023
1,230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef unsigned long long ull;
  6. typedef long long ll;
  7. typedef long double ld;
  8. typedef pair<int, int> pii;
  9. typedef pair<ll, ll> pll;
  10. typedef pair<ull, ull> puu;
  11.  
  12. #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  13. #define file_in freopen("input.txt", "r", stdin);
  14. #define all(x) (x).begin(), (x).end()
  15. #define sz(x) (int)x.size()
  16. #define fi first
  17. #define se second
  18.  
  19. template<typename T> istream& operator>>(istream& in, vector<T> &v) { for (auto &el : v) in >> el; return in; }
  20. template<typename T> ostream& operator<<(ostream& out, vector<T> &v) { for (auto &el : v) out << el << " "; return out; }
  21. template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &v) { in >> v.first >> v.second; return in; }
  22. template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &v) { cout << v.first << " " << v.second; return out; }
  23.  
  24. int main() {
  25.     fast  
  26.     // file_in
  27.  
  28.     int n;
  29.     cin >> n;
  30.     n = (1 << n);
  31.     vector<int> a(n);
  32.     cin >> a;
  33.     if (n == 2) {
  34.         cout << 2 << '\n';
  35.         return 0;
  36.     }
  37.     int mask = 0, cnt = 0;
  38.     ll res = 0;
  39.     unordered_map<int, vector<int>> ht;
  40.     for (int i = 0; i < n; ++i) {
  41.         a[i] = min(a[i], n - a[i] - 1);
  42.         if ((mask >> a[i]) & 1) ++cnt;
  43.         mask ^= 1 << a[i];
  44.         if (ht[mask].empty()) {
  45.             ht[mask].resize(2);
  46.         }
  47.         res += ht[mask][cnt % 2];
  48.         ht[mask][cnt % 2]++;
  49.     }
  50.     cout << 1ll * n * (n + 1) / 2 - res - ht[0][0] << '\n';
  51.     return 0;
  52. }
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement