Submission #1054115

#TimeUsernameProblemLanguageResultExecution timeMemory
1054115juicy즐거운 사진 수집 (JOI13_collecting)C++17
100 / 100
733 ms62036 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif const int N = 21; int n, q; int s[2][1 << N], cnt[2][N]; void upd(int *s, int *cnt, int i, int id = 1, int l = 1, int r = 1 << n, int lvl = 0) { if (l == r) { s[id] ^= 1; return; } int md = (l + r) / 2; if (i <= md) { upd(s, cnt, i, id * 2, l, md, lvl + 1); } else { upd(s, cnt, i, id * 2 + 1, md + 1, r, lvl + 1); } if (~s[id]) { --cnt[lvl]; } s[id] = s[id * 2] == s[id * 2 + 1] ? s[id * 2] : -1; if (~s[id]) { ++cnt[lvl]; } } long long qry() { long long res = 0; for (int i = 0; i <= n; ++i) { res += (1LL << 2 * i) - (long long) cnt[0][i] * cnt[1][i]; } return res * 4 + 1; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> q; for (int i = 0; i <= n; ++i) { for (auto it : {0, 1}) { cnt[it][i] = 1 << i; } } while (q--) { int t, x; cin >> t >> x; upd(s[t], cnt[t], x); cout << qry() << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...