Submission #236211

#TimeUsernameProblemLanguageResultExecution timeMemory
236211VEGAnnDojave (COCI17_dojave)C++14
112 / 140
4097 ms29200 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) #define a3 array<int, 3> #define MP make_pair using namespace std; typedef unsigned long long ull; typedef long long ll; const int N = (1 << 20); const int oo = 2e9; map<pair<ull, int>, int> mem; ull vl[N], ans = 0; pair<ull, int> chk; int m, n, a[N]; mt19937_64 rnd(chrono::system_clock().now().time_since_epoch().count()); void calc(int l, int r){ if (l == r) return; int md = (l + r) >> 1; calc(l, md); calc(md + 1, r); mem.clear(); ull sum = 0; int xr = 0; for (int i = md; i >= l; i--){ sum += vl[a[i]]; xr ^= a[i]; mem[MP(sum, xr)]++; } sum = 0; xr = 0; for (int i = md + 1; i <= r; i++){ sum += vl[a[i]]; xr ^= a[i]; chk = MP(ull(0) - sum, xr); if (mem.find(chk) != mem.end()) ans += mem[chk]; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef _LOCAL freopen("in.txt","r",stdin); #endif // _LOCAL cin >> m; n = (1 << m); if (m == 1){ cout << 2; return 0; } for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++){ int obr = ((n - 1) ^ i); if (obr < i) continue; vl[i] = rnd(); vl[obr] = ull(0) - vl[i]; } calc(0, n - 1); cout << ull(n) * (ull(n) + 1) / 2 - ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...