This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct SegmentTree{
int n, depth;
vector<int> d, cnt;
void init(int _depth){
depth = _depth;
n = (1 << depth);
cnt.assign(depth, 0);
d.assign(n * 4, 0);
cnt[0] = 1;
for(int i = 1; i < depth; i++)
cnt[i] = cnt[i - 1] * 2;
}
void update(int id, int depth, int l, int r, int pos){
if (pos < l || r < pos)
return;
if (l == r){
d[id] ^= 1;
return;
}
cnt[depth] -= (d[id] == 0 || d[id] == r - l + 1);
int mid = (l + r) >> 1;
update(id << 1, depth + 1, l, mid, pos);
update(id << 1 | 1, depth + 1, mid + 1, r, pos);
d[id] = d[id << 1] + d[id << 1 | 1];
cnt[depth] += (d[id] == 0 || d[id] == r - l + 1);
}
void update(int pos){
update(1, 0, 1, n, pos);
}
} ST[2];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
for(int i = 0; i < 2; i++)
ST[i].init(n);
while (q--){
int id, pos;
cin >> id >> pos;
ST[id].update(pos);
ll res = 1;
for(int i = 1; i <= n; i++)
res = res * 4 + 1;
for(int i = 0; i < n; i++)
res -= (ll) ST[0].cnt[i] * ST[1].cnt[i] * 4;
cout << res << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |