Submission #821765

# Submission time Handle Problem Language Result Execution time Memory
821765 2023-08-11T15:52:44 Z nonono 즐거운 사진 수집 (JOI13_collecting) C++14
0 / 100
2858 ms 106588 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 20;

int n, q;
int f[mxN + 5];

struct seg_tree {
    vector<int> ST, cnt;
    
    void init(int n) {
        ST.resize((1 << n) * 4);
        cnt.resize(n + 5);
        
        for(int i = 1; i <= (1 << n) * 4; i ++) ST[i] = 0;
        for(int i = 0; i <= n; i ++) cnt[i] = 0;
        
        cnt[n] ++ ;
    }
    
    void update(int id, int l, int r, int x) {
        int k = log2(r - l + 1);
        if(cnt[k] > 0) {
            cnt[k] -- ;
            cnt[k - 1] += 2;
        }
        
        if(l == r) {
            ST[id] = !ST[id];
            cnt[k] ++ ;
            return ;
        }
        
        int mid = (l + r) / 2;
        if(x <= mid) update(id * 2, l, mid, x); 
        else 
            update(id * 2 + 1, mid + 1, r, x);
        
        ST[id] = ST[id * 2] + ST[id * 2 + 1];
        if(!ST[id] && ST[id] == r - l + 1) {
            cnt[k] ++ ;
            cnt[k - 1] -= 2;
        }
    }
};

seg_tree a, b;

signed main() {
 
    cin.tie(0)->sync_with_stdio(0);
    
    cin >> n >> q;
    
    f[0] = 1;
    for(int i = 1; i <= n; i ++) {
        f[i] = 4 * f[i - 1] + 1;
    }
    
    a.init(n);
    b.init(n);
    
    while(q --) {
        int t, x;
        cin >> t >> x;
        
        if(!t) a.update(1, 1, 1 << n, x);
        if(t) b.update(1, 1, 1 << n, x);
        
        int sum = 0;
        for(int i = 0; i <= n; i ++) {
            for(int j = 0; j <= n; j ++) {
                int k = abs(i - j);
                sum += (f[min(i, j)] - 1) * (1 << k) * a.cnt[i] * b.cnt[j]; 
            }        
        }
        
        cout << f[n] - sum << "\n";
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2858 ms 106588 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -