#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = (1<<21);
int n,q;
int rtree[MAXN],ctree[MAXN];
long long rsum[MAXN],csum[MAXN];
void update(int node,int st,int ed,int pos,int *tree,long long *sum,int dep){
if(pos > ed || pos < st)return;
if(st == ed){
tree[node] ^= 1;
return;
}
if(tree[node] == 0 || tree[node] == (1LL <<(n-dep))) sum[dep]--;
update(node*2,st,(st+ed)/2,pos,tree,sum,dep+1);
update(node*2+1,(st+ed)/2+1,ed,pos,tree,sum,dep+1);
tree[node] = tree[node * 2] + tree[node * 2 +1];
if(tree[node] == 0 || tree[node] == (1LL <<(n-dep))) sum[dep]++;
return;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> q;
for(int i = 0; i <= n; i++){
rsum[i] = csum[i] = (1LL << i);
}
for(int i = 1; i <= q; i++){
int type; int line;
cin >> type >> line;
if(type == 0) update(1,1,(1<<n),line,rtree,rsum,0);
else update(1,1,(1<<n),line,ctree,csum,0);
long long ret = 0;
long long last = 0;
for(int j = 0; j <= n; j++){
long long a = 1<<j;
long long b = 1<<j;
ret += a * b;
ret -= 4 * last;
last = rsum[j] * csum[j];
}
cout<<ret<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
552 KB |
Output is correct |
4 |
Correct |
2 ms |
552 KB |
Output is correct |
5 |
Correct |
2 ms |
664 KB |
Output is correct |
6 |
Correct |
2 ms |
664 KB |
Output is correct |
7 |
Correct |
2 ms |
664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
728 KB |
Output is correct |
2 |
Correct |
3 ms |
728 KB |
Output is correct |
3 |
Correct |
3 ms |
728 KB |
Output is correct |
4 |
Correct |
3 ms |
728 KB |
Output is correct |
5 |
Correct |
3 ms |
728 KB |
Output is correct |
6 |
Correct |
3 ms |
728 KB |
Output is correct |
7 |
Correct |
2 ms |
728 KB |
Output is correct |
8 |
Correct |
2 ms |
728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2129 ms |
43832 KB |
Output is correct |
2 |
Correct |
2215 ms |
43832 KB |
Output is correct |
3 |
Correct |
1794 ms |
43832 KB |
Output is correct |
4 |
Correct |
2013 ms |
44208 KB |
Output is correct |
5 |
Correct |
2059 ms |
44208 KB |
Output is correct |
6 |
Correct |
2015 ms |
44208 KB |
Output is correct |
7 |
Correct |
2048 ms |
44208 KB |
Output is correct |
8 |
Correct |
2118 ms |
44208 KB |
Output is correct |
9 |
Correct |
1731 ms |
44208 KB |
Output is correct |
10 |
Correct |
1752 ms |
44208 KB |
Output is correct |
11 |
Correct |
1965 ms |
44208 KB |
Output is correct |
12 |
Correct |
1968 ms |
44208 KB |
Output is correct |
13 |
Correct |
2001 ms |
44208 KB |
Output is correct |