Submission #236222

#TimeUsernameProblemLanguageResultExecution timeMemory
236222VEGAnnDojave (COCI17_dojave)C++14
140 / 140
953 ms45772 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) #define PB push_back #define MP make_pair #define all(x) x.begin(),x.end() using namespace std; typedef unsigned long long ull; typedef long long ll; const int N = (1 << 20); const int oo = 2e9; vector<pair<ull, int> > vc; ull vl[N], ans = 0; int m, n, a[N], kol[N]; mt19937_64 rnd(chrono::system_clock().now().time_since_epoch().count()); 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]; } vc.PB(MP(0, 0)); ull sum = 0; int xr = 0; for (int i = 0; i < n; i++){ sum += vl[a[i]]; xr ^= a[i]; vc.PB(MP(sum, xr)); } sort(all(vc)); vc.resize(unique(all(vc)) - vc.begin()); kol[0]++; sum = 0; xr = 0; for (int i = 0; i < n; i++){ sum += vl[a[i]]; xr ^= a[i]; int id = lower_bound(all(vc), MP(sum, xr)) - vc.begin(); ans += kol[id]; kol[id]++; } 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...