#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int N, M, Q;
int Log[1 << 20];
pii mrg(pii a, pii b) {
if(a > b) swap(a, b);
if(a.first == b.first) return {a.first, a.second + b.second};
else return a;
}
struct BIT {
vector<pii> tree;
int level[20];
void init() {
tree = vector<pii>(4 * M);
build(0, M - 1, 1);
}
void build(int l, int r, int n) {
if(l == r) {
tree[n] = {0, 1};
return;
}
int m = (l + r)>>1;
build(l, m, 2*n);
build(m + 1, r, 2*n + 1);
tree[n] = mrg(tree[2*n], tree[2*n + 1]);
}
void upd(int idx, int l, int r, int n) {
if(idx < l || r < idx) return;
if(l == r) {
tree[n].first ^= 1;
return;
}
int m = (l + r)>>1;
upd(idx, l, m, 2*n);
upd(idx, m + 1, r, 2*n + 1);
int x = Log[ (m + 1) & -(m + 1) ];
if(tree[n].second != r - l + 1) {
level[x]--;
}
tree[n] = mrg(tree[2*n], tree[2*n + 1]);
if(tree[n].second != r - l + 1) {
level[x]++;
}
}
} bit1, bit2;
int main() {
for(int i = 0; i < 20; i++) Log[1 << i] = i;
scanf("%d %d", &N, &Q);
M = 1 << N;
bit1.init();
bit2.init();
for(int i = 0; i < Q; i++) {
int t, x; scanf("%d %d", &t, &x);
x--;
if(t == 0) bit1.upd(x, 0, M - 1, 1);
if(t == 1) bit2.upd(x, 0, M - 1, 1);
ll cnt = 0;
for(int j = 0; j < N; j++) {
cnt += 1LL * bit1.level[j] * (1 << (N - 1 - j));
cnt += 1LL * bit2.level[j] * (1 << (N - 1 - j));
cnt -= 1LL * bit1.level[j] * bit2.level[j];
}
printf("%lld\n", 1 + 4 * cnt);
}
}
Compilation message
collecting.cpp: In function 'int main()':
collecting.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &Q);
~~~~~^~~~~~~~~~~~~~~~~
collecting.cpp:62:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int t, x; scanf("%d %d", &t, &x);
~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
676 KB |
Output is correct |
4 |
Correct |
2 ms |
692 KB |
Output is correct |
5 |
Correct |
2 ms |
696 KB |
Output is correct |
6 |
Correct |
2 ms |
704 KB |
Output is correct |
7 |
Correct |
2 ms |
756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1040 KB |
Output is correct |
2 |
Correct |
4 ms |
1176 KB |
Output is correct |
3 |
Correct |
4 ms |
1180 KB |
Output is correct |
4 |
Correct |
3 ms |
1320 KB |
Output is correct |
5 |
Correct |
3 ms |
1320 KB |
Output is correct |
6 |
Correct |
4 ms |
1320 KB |
Output is correct |
7 |
Correct |
3 ms |
1332 KB |
Output is correct |
8 |
Correct |
4 ms |
1468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2895 ms |
111432 KB |
Output is correct |
2 |
Correct |
2846 ms |
128724 KB |
Output is correct |
3 |
Correct |
2424 ms |
128724 KB |
Output is correct |
4 |
Correct |
2722 ms |
163372 KB |
Output is correct |
5 |
Correct |
2423 ms |
180340 KB |
Output is correct |
6 |
Correct |
2614 ms |
196840 KB |
Output is correct |
7 |
Correct |
2691 ms |
214616 KB |
Output is correct |
8 |
Correct |
2482 ms |
226720 KB |
Output is correct |
9 |
Correct |
2371 ms |
226720 KB |
Output is correct |
10 |
Correct |
2620 ms |
226720 KB |
Output is correct |
11 |
Runtime error |
2604 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
12 |
Halted |
0 ms |
0 KB |
- |