#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 20;
int n, q;
int s[2][1 << N + 1], 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;
}
Compilation message
collecting.cpp:14:17: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
14 | int s[2][1 << N + 1], cnt[2][N];
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2516 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
703 ms |
61580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |