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 <stdio.h>
#define H_ 20
#define N_ (1 << H_)
int h_, n_;
void pul(int *st, int *kk, int i, int h) {
int l = i << 1, r = l | 1;
if (st[i] != -1)
kk[h]--;
st[i] = st[l] == -1 || st[r] == -1 || st[l] != st[r] ? -1 : st[l];
if (st[i] != -1)
kk[h]++;
}
void update(int *st, int *kk, int i) {
int h;
i += n_;
st[i] ^= 1;
for (h = 1; h <= h_; h++)
pul(st, kk, i >> h, h);
}
int main() {
static int st1[N_ * 2], st2[N_ * 2], kk1[H_ + 1], kk2[H_ + 1];
int q, h;
scanf("%d%d", &h_, &q), n_ = 1 << h_;
for (h = 0; h <= h_; h++)
kk1[h] = kk2[h] = n_ >> h;
while (q--) {
int t, h, i, j;
long long ans;
scanf("%d", &t);
if (t == 0) {
scanf("%d", &i), i--;
update(st1, kk1, i);
} else {
scanf("%d", &j), j--;
update(st2, kk2, j);
}
ans = 0;
for (h = 0; h <= h_; h++)
ans += (long long) (n_ >> h) * (n_ >> h) - (long long) kk1[h] * kk2[h];
ans = ans * 4 + 1;
printf("%lld\n", ans);
}
return 0;
}
Compilation message (stderr)
collecting.c: In function 'main':
collecting.c:31:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%d%d", &h_, &q), n_ = 1 << h_;
| ^~~~~~~~~~~~~~~~~~~~~~
collecting.c:38:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | scanf("%d", &t);
| ^~~~~~~~~~~~~~~
collecting.c:40:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d", &i), i--;
| ^~~~~~~~~~~~~~~
collecting.c:43:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d", &j), j--;
| ^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |