이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
ll seg[1 << 22];
ll seg1[1 << 22];
ll cc[1 << 20 + 1];
ll cc1[1 << 20 + 1];
ll n, m;
ll check[22];
ll check1[22];
ll dap;
ll update(ll pos, ll val, ll node, ll x, ll y,ll depth)
{
if (pos < x || y < pos)return seg[node];
if (x == y)return seg[node] = val;
ll mid = (x + y) / 2;
ll gap = 2 * (1 << (depth + 1));
if (seg[node] == 0 || seg[node] == y - x + 1) {
check[depth]++;
dap += (gap - gap / (1 << depth)*check1[depth]);
}
seg[node] = update(pos, val, node * 2, x, mid,depth+1) + update(pos, val, node * 2 + 1, mid + 1, y,depth+1);
if (seg[node] == 0 || seg[node] == y - x + 1)
{
check[depth]--;
dap -= (gap - gap / (1 << depth)*check1[depth]);
}
return seg[node];
}
ll update1(ll pos, ll val, ll node, ll x, ll y,ll depth)
{
if (pos < x || y < pos)return seg1[node];
if (x == y)return seg1[node] = val;
ll mid = (x + y) / 2;
ll gap = 2 * (1 << (depth + 1));
if (seg1[node] == 0 || seg1[node] == y - x + 1) {
check1[depth]++;
dap += (gap - gap / (1 << depth)*check[depth]);
}
seg1[node] = update1(pos, val, node * 2, x, mid, depth + 1) + update1(pos, val, node * 2 + 1, mid + 1, y, depth + 1);
if (seg1[node] == 0 || seg1[node] == y - x + 1)
{
check1[depth]--;
dap -= (gap - gap / (1 << depth)*check[depth]);
}
return seg1[node];
}
int main()
{
scanf("%lld %lld", &n, &m);
for (ll i = 1; i <= m; i++)
{
ll q, w;
scanf("%lld %lld", &q, &w);
if (q == 0) {
cc[w] ^= 1;
update(w, cc[w], 1, 1, (1 << n),0);
}
else
{
cc1[w] ^= 1;
update1(w, cc1[w], 1, 1, (1 << n),0);
}
printf("%lld\n", dap+1);
}
}
컴파일 시 표준 에러 (stderr) 메시지
collecting.cpp:8:15: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
ll cc[1 << 20 + 1];
~~~^~~
collecting.cpp:9:16: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
ll cc1[1 << 20 + 1];
~~~^~~
collecting.cpp: In function 'int main()':
collecting.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~~~~~
collecting.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &q, &w);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |