結果

問題 No.961 Vibrant Fillumination
ユーザー koprickykopricky
提出日時 2019-12-08 01:51:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 922 ms / 5,000 ms
コード長 5,710 bytes
コンパイル時間 1,015 ms
コンパイル使用メモリ 86,016 KB
実行使用メモリ 89,340 KB
最終ジャッジ日時 2023-08-30 20:59:09
合計ジャッジ時間 37,670 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,636 KB
testcase_01 AC 3 ms
9,700 KB
testcase_02 AC 530 ms
72,488 KB
testcase_03 AC 550 ms
76,500 KB
testcase_04 AC 566 ms
78,728 KB
testcase_05 AC 574 ms
76,684 KB
testcase_06 AC 533 ms
77,316 KB
testcase_07 AC 552 ms
76,476 KB
testcase_08 AC 547 ms
76,324 KB
testcase_09 AC 556 ms
76,476 KB
testcase_10 AC 919 ms
88,392 KB
testcase_11 AC 906 ms
89,192 KB
testcase_12 AC 922 ms
88,152 KB
testcase_13 AC 912 ms
89,340 KB
testcase_14 AC 917 ms
88,320 KB
testcase_15 AC 884 ms
89,088 KB
testcase_16 AC 900 ms
88,360 KB
testcase_17 AC 883 ms
89,180 KB
testcase_18 AC 915 ms
89,308 KB
testcase_19 AC 911 ms
88,052 KB
testcase_20 AC 913 ms
89,160 KB
testcase_21 AC 890 ms
87,620 KB
testcase_22 AC 888 ms
89,140 KB
testcase_23 AC 876 ms
87,808 KB
testcase_24 AC 883 ms
89,116 KB
testcase_25 AC 920 ms
87,716 KB
testcase_26 AC 285 ms
76,484 KB
testcase_27 AC 476 ms
89,288 KB
testcase_28 AC 285 ms
68,020 KB
testcase_29 AC 535 ms
87,660 KB
testcase_30 AC 630 ms
89,324 KB
testcase_31 AC 409 ms
87,744 KB
testcase_32 AC 414 ms
89,300 KB
testcase_33 AC 2 ms
4,948 KB
testcase_34 AC 645 ms
75,400 KB
testcase_35 AC 595 ms
78,752 KB
testcase_36 AC 617 ms
78,156 KB
testcase_37 AC 632 ms
77,960 KB
testcase_38 AC 593 ms
77,896 KB
testcase_39 AC 602 ms
77,500 KB
testcase_40 AC 582 ms
77,448 KB
testcase_41 AC 603 ms
77,544 KB
testcase_42 AC 602 ms
77,288 KB
testcase_43 AC 622 ms
77,128 KB
testcase_44 AC 629 ms
77,704 KB
testcase_45 AC 623 ms
77,576 KB
testcase_46 AC 634 ms
78,644 KB
testcase_47 AC 605 ms
79,028 KB
testcase_48 AC 620 ms
79,012 KB
testcase_49 AC 632 ms
78,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>

const int MAX_N = 50003;
const int MAX_Q = 50003;
const int WIDTH = 2000;
const int LEN = 2 * MAX_N / WIDTH + 1;

struct info {
    int lower, upper, color;
    info(){}
    info(const int _lower, const int _upper, const int _color)
        : lower(_lower), upper(_upper), color(_color){}
};

info xborder[2 * MAX_N], yborder[2 * MAX_N];
unsigned long long h[MAX_N], memo[LEN][LEN];
unsigned short sz[LEN][LEN], cnt[LEN][LEN][2 * WIDTH], color_table[LEN][LEN][2 * WIDTH];
int border_color[LEN][LEN][2 * WIDTH], kp[2 * WIDTH];
int X[2 * MAX_N], Y[2 * MAX_N], C[MAX_N], used[MAX_N];
int N, Q;

void transform_rectangle(){
    std::vector<std::vector<int> > tmp(N);
    std::vector<int> idX(2 * N, 0), idY(2 * N, 0);
    for(int i = 0; i < N; ++i){
        int a, b, c, d, e;
        std::cin >> a >> b >> c >> d >> e;
        X[2 * i] = a, X[2 * i + 1] = c, Y[2 * i] = b, Y[2 * i + 1] = d;
        tmp[i] = {a, b, c, d, e};
    }
    std::sort(X, X + 2 * N), std::sort(Y, Y + 2 * N);
    for(const std::vector<int>& in : tmp){
        const int a = std::lower_bound(X, X + 2 * N, in[0]) - X + idX[in[0]]++;
        const int b = std::lower_bound(Y, Y + 2 * N, in[1]) - Y + idY[in[1]]++;
        const int c = std::lower_bound(X, X + 2 * N, in[2]) - X + idX[in[2]]++;
        const int d = std::lower_bound(Y, Y + 2 * N, in[3]) - Y + idY[in[3]]++;
        const int e = in[4];
        xborder[a] = {b, d, e}, xborder[c] = {b, d, -e}, yborder[b] = {a, c, e}, yborder[d] = {a, c, -e};
    }
}

void pre_calc(){
    unsigned long long cur_hash = 0;
    int curx = -1, cury = -1;
    const int length = (2 * N - 2) / WIDTH + 1;
    for(int i = 0; i < length; ++i){
        for(int j = 0; j < length; ++j){
            std::vector<int> color;
            auto ct = color_table[i][j];
            const int stx = i * WIDTH + 1, sty = j * WIDTH + 1;
            for(int curx = stx; curx < std::min((i + 1) * WIDTH, 2 * N - 1); ++curx){
                const int c = xborder[curx].color;
                if(c > 0){
                    if(!used[c]){
                        color.push_back(c), ct[used[c] = (int)color.size()] = c;
                    }
                    border_color[i][j][curx - stx] = used[c];
                }else{
                    if(!used[-c]){
                        color.push_back(-c), ct[used[-c] = (int)color.size()] = -c;
                    }
                    border_color[i][j][curx - stx] = -used[-c];
                }
            }
            for(int cury = sty; cury < std::min((j + 1) * WIDTH, 2 * N - 1); ++cury){
                const int c = yborder[cury].color;
                if(c > 0){
                    if(!used[c]){
                        color.push_back(c), ct[used[c] = (int)color.size()] = c;
                    }
                    border_color[i][j][cury + WIDTH - sty] = used[c];
                }else{
                    if(!used[-c]){
                        color.push_back(-c), ct[used[-c] = (int)color.size()] = -c;
                    }
                    border_color[i][j][cury + WIDTH - sty] = -used[-c];
                }
            }
            sz[i][j] = (int)color.size();
            for(const int c : color) used[c] = 0;
        }
    }
    for(int i = 0; i < length; ++i){
        memset(C, 0, sizeof(C)), cur_hash = 0, curx = i * WIDTH, cury = -1;
        for(int j = 0; j < length; ++j){
            while(cury < j * WIDTH){
                ++cury;
                if(yborder[cury].lower <= curx && curx < yborder[cury].upper){
                    const int c = yborder[cury].color;
                    if(c > 0){
                        if(++C[c] == 1) cur_hash ^= h[c];
                    }else{
                        if(--C[-c] == 0) cur_hash ^= h[-c];
                    }
                }
            }
            memo[i][j] = cur_hash;
            for(int k = 1; k <= sz[i][j]; ++k){
                cnt[i][j][k] = C[color_table[i][j][k]];
            }
        }
    }
}

unsigned long long query(const int p, const int q){
    const int x = std::upper_bound(X, X + 2 * N, p) - X - 1;
    const int y = std::upper_bound(Y, Y + 2 * N, q) - Y - 1;
    if(x < 0 || x >= 2 * N - 1 || y < 0 || y >= 2 * N - 1) return 0ULL;
    const int zx = x / WIDTH, zy = y / WIDTH;
    unsigned long long cur_hash = memo[zx][zy];
    for(int i = 1; i <= sz[zx][zy]; ++i) kp[i] = cnt[zx][zy][i];
    auto ct = color_table[zx][zy];
    auto bc = border_color[zx][zy];
    const int stx = zx * WIDTH + 1, sty = zy * WIDTH + 1;
    int curx = stx - 1, cury = sty - 1;
    while(curx < x){
        ++curx;
        if(xborder[curx].lower <= cury && cury < xborder[curx].upper){
            const int c = bc[curx - stx];
            if(c > 0){
                if(++kp[c] == 1) cur_hash ^= h[ct[c]];
            }else{
                if(--kp[-c] == 0) cur_hash ^= h[ct[-c]];
            }
        }
    }
    while(cury < y){
        ++cury;
        if(yborder[cury].lower <= curx && curx < yborder[cury].upper){
            const int c = bc[cury + WIDTH - sty];
            if(c > 0){
                if(++kp[c] == 1) cur_hash ^= h[ct[c]];
            }else{
                if(--kp[-c] == 0) cur_hash ^= h[ct[-c]];
            }
        }
    }
    return cur_hash;
}

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cin >> N;
    for(int i = 1; i <= N; ++i){
        std::cin >> h[i];
    }
    transform_rectangle();
    std::cin >> Q;
    pre_calc();
    for(int i = 0; i < Q; ++i){
        int p, q;
        std::cin >> p >> q;
        std::cout << query(p, q) << "\n";
    }
    return 0;
}
0