Submission #56960

#TimeUsernameProblemLanguageResultExecution timeMemory
56960choikiwon즐거운 사진 수집 (JOI13_collecting)C++17
30 / 100
2895 ms263168 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; int N, M, Q; int Log[1 << 20]; pii mrg(pii a, pii b) { if(a > b) swap(a, b); if(a.first == b.first) return {a.first, a.second + b.second}; else return a; } struct BIT { vector<pii> tree; int level[20]; void init() { tree = vector<pii>(4 * M); build(0, M - 1, 1); } void build(int l, int r, int n) { if(l == r) { tree[n] = {0, 1}; return; } int m = (l + r)>>1; build(l, m, 2*n); build(m + 1, r, 2*n + 1); tree[n] = mrg(tree[2*n], tree[2*n + 1]); } void upd(int idx, int l, int r, int n) { if(idx < l || r < idx) return; if(l == r) { tree[n].first ^= 1; return; } int m = (l + r)>>1; upd(idx, l, m, 2*n); upd(idx, m + 1, r, 2*n + 1); int x = Log[ (m + 1) & -(m + 1) ]; if(tree[n].second != r - l + 1) { level[x]--; } tree[n] = mrg(tree[2*n], tree[2*n + 1]); if(tree[n].second != r - l + 1) { level[x]++; } } } bit1, bit2; int main() { for(int i = 0; i < 20; i++) Log[1 << i] = i; scanf("%d %d", &N, &Q); M = 1 << N; bit1.init(); bit2.init(); for(int i = 0; i < Q; i++) { int t, x; scanf("%d %d", &t, &x); x--; if(t == 0) bit1.upd(x, 0, M - 1, 1); if(t == 1) bit2.upd(x, 0, M - 1, 1); ll cnt = 0; for(int j = 0; j < N; j++) { cnt += 1LL * bit1.level[j] * (1 << (N - 1 - j)); cnt += 1LL * bit2.level[j] * (1 << (N - 1 - j)); cnt -= 1LL * bit1.level[j] * bit2.level[j]; } printf("%lld\n", 1 + 4 * cnt); } }

Compilation message (stderr)

collecting.cpp: In function 'int main()':
collecting.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &Q);
     ~~~~~^~~~~~~~~~~~~~~~~
collecting.cpp:62:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int t, x; scanf("%d %d", &t, &x);
                   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...