이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, q, cnt[2][25], chk[2][1234567], ans;
struct segtree {
ll val[4444444];
ll unif (ll S, ll E, ll P) {
return (val[P] == (E-S+1) || val[P] == 0);
}
void init (ll T, ll D, ll S, ll E, ll P) {
if(D == n) return;
cnt[T][D] += unif(S, E, P);
ans -= unif(S, E, P) * cnt[T^1][D] * 4;
ll mid = (S+E)/2;
init(T, D+1, S, mid, 2*P);
init(T, D+1, mid+1, E, 2*P+1);
}
void update (ll T, ll D, ll S, ll E, ll P, ll X, ll V) {
if(D == n) {val[P] += V; return;}
cnt[T][D] -= unif(S, E, P);
ans += unif(S, E, P) * cnt[T^1][D] * 4;
val[P] += V;
cnt[T][D] += unif(S, E, P);
ans -= unif(S, E, P) * cnt[T^1][D] * 4;
ll mid = (S+E)/2;
if(X <= mid) update(T, D+1, S, mid, 2*P, X, V);
else update(T, D+1, mid+1, E, 2*P+1, X, V);
}
} seg[2];
int main()
{
scanf("%lld%lld",&n,&q);
ans = (1ll << (2*n)) + ((1ll << (2*n)) - 1) / 3;
seg[0].init(0, 0, 1, (1<<n), 1);
seg[1].init(1, 0, 1, (1<<n), 1);
while(q--) {
ll A, B, V;
scanf("%lld%lld",&A,&B);
V = (chk[A][B] ^ 1) - chk[A][B];
chk[A][B] ^= 1;
seg[A].update(A, 0, 1, (1<<n), 1, B, V);
printf("%lld\n",ans);
}
}
컴파일 시 표준 에러 (stderr) 메시지
collecting.cpp: In function 'int main()':
collecting.cpp:34:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld",&n,&q);
^
collecting.cpp:40:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld",&A,&B);
^| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |