답안 #16827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
16827 2015-10-02T11:58:00 Z gs14004 즐거운 사진 수집 (JOI13_collecting) C++14
30 / 100
1199 ms 18104 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <utility>
#include <bitset>
#include <iostream>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;

int n, q;

struct seg{
    int tree[1<<21];
    int cnts[20];
    void init(){
        for(int i=0; i<n; i++){
            cnts[i] = (1<<i);
        }
    }
    void flip(int x){
        x |= (1<<n);
        tree[x] ^= 1;
        for(int dep = n-1; dep >= 0; dep--){
            x >>= 1;
            if(tree[x] == (1 << (n - dep)) || tree[x] == 0){
                cnts[dep]--; // 
            }
            tree[x] = tree[2*x] + tree[2*x+1];
            if(tree[x] == (1 << (n - dep)) || tree[x] == 0){
                cnts[dep]++;
            }
        }
    }
}px, py;

int main(){
    scanf("%d %d",&n,&q);
    px.init();
    py.init();
    for(int i=0; i<q; i++){
        int t, p;
        scanf("%d %d",&t, &p);
        p--;
        if(t) px.flip(p);
        else py.flip(p);
        int ret = 0;
        for(int i=0; i<n; i++){
            int rcnt = (1 << (n - i - 1));
            ret += rcnt * rcnt - px.cnts[n-1-i] * py.cnts[n-1-i];
        }
        printf("%d\n",ret * 4 + 1);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 18104 KB Output is correct
2 Correct 0 ms 18104 KB Output is correct
3 Correct 0 ms 18104 KB Output is correct
4 Correct 0 ms 18104 KB Output is correct
5 Correct 0 ms 18104 KB Output is correct
6 Correct 0 ms 18104 KB Output is correct
7 Correct 0 ms 18104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 18104 KB Output is correct
2 Correct 0 ms 18104 KB Output is correct
3 Correct 0 ms 18104 KB Output is correct
4 Correct 1 ms 18104 KB Output is correct
5 Correct 0 ms 18104 KB Output is correct
6 Correct 0 ms 18104 KB Output is correct
7 Correct 0 ms 18104 KB Output is correct
8 Correct 0 ms 18104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1199 ms 18104 KB Output isn't correct
2 Halted 0 ms 0 KB -