Submission #102796

#TimeUsernameProblemLanguageResultExecution timeMemory
102796njchung99즐거운 사진 수집 (JOI13_collecting)C++14
100 / 100
3350 ms94280 KiB
#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); } }

Compilation message (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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...