結果

問題 No.961 Vibrant Fillumination
ユーザー koprickykopricky
提出日時 2019-12-07 22:06:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,311 bytes
コンパイル時間 935 ms
コンパイル使用メモリ 88,888 KB
実行使用メモリ 18,188 KB
最終ジャッジ日時 2023-08-27 04:42:58
合計ジャッジ時間 25,735 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,488 KB
testcase_01 AC 4 ms
8,248 KB
testcase_02 AC 318 ms
15,572 KB
testcase_03 AC 320 ms
15,708 KB
testcase_04 AC 322 ms
15,664 KB
testcase_05 AC 320 ms
15,584 KB
testcase_06 AC 323 ms
15,696 KB
testcase_07 AC 330 ms
15,772 KB
testcase_08 AC 324 ms
15,580 KB
testcase_09 AC 323 ms
15,720 KB
testcase_10 AC 406 ms
15,704 KB
testcase_11 AC 402 ms
15,772 KB
testcase_12 AC 411 ms
15,580 KB
testcase_13 AC 399 ms
15,624 KB
testcase_14 AC 419 ms
15,572 KB
testcase_15 AC 372 ms
15,624 KB
testcase_16 AC 404 ms
15,576 KB
testcase_17 AC 373 ms
15,584 KB
testcase_18 AC 406 ms
15,628 KB
testcase_19 AC 398 ms
15,580 KB
testcase_20 AC 402 ms
15,604 KB
testcase_21 AC 375 ms
15,576 KB
testcase_22 AC 378 ms
15,592 KB
testcase_23 AC 377 ms
15,584 KB
testcase_24 AC 392 ms
15,688 KB
testcase_25 AC 394 ms
15,580 KB
testcase_26 AC 233 ms
15,708 KB
testcase_27 AC 223 ms
15,572 KB
testcase_28 AC 257 ms
15,568 KB
testcase_29 AC 256 ms
15,724 KB
testcase_30 AC 3,866 ms
13,808 KB
testcase_31 TLE -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MAX_N = 50000;

struct info {
    int lower, upper, color;
    info() : info(2 * MAX_N + 1, -1, 0){}
    info(const int _lower, const int _upper, const int _color)
        : lower(_lower), upper(_upper), color(_color){}
};

std::vector<info> upx[2 * MAX_N], upy[2 * MAX_N];
int C[MAX_N];

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int N;
    std::cin >> N;
    std::vector<unsigned long long> h(N);
    for(int i = 0; i < N; ++i){
        std::cin >> h[i];
    }
    for(int i = 0; i < N; ++i){
        int a, b, c, d, e;
        std::cin >> a >> b >> c >> d >> e;
        upx[a].emplace_back(b, d, e), upx[c].emplace_back(b, d, -e);
        upy[b].emplace_back(a, c, e), upy[d].emplace_back(a, c, -e);
    }
    int Q;
    std::cin >> Q;
    std::vector<std::pair<int, int> > z(Q);
    std::vector<int> ord(Q);
    std::iota(ord.begin(), ord.end(), 0);
    for(int i = 0; i < Q; ++i){
        int p, q;
        std::cin >> p >> q;
        z[i] = {p, q};
    }
    const int width = 2 * ceil(sqrt(N));
    std::sort(ord.begin(), ord.end(), [&](const int a, const int b){
        const int u = z[a].first / width, v = z[b].first / width;
        return (u == v) ? (z[a].second < z[b].second) : (u < v);
    });
    std::vector<unsigned long long> ans(Q);
    unsigned long long cur_hash = 0;
    int prv = -1, curx = -1, cury = -1;
    for(const int id : ord){
        const int cur = z[id].first / width;
        if(prv != cur){
            memset(C, 0, sizeof(C)), cur_hash = 0, prv = cur, curx = cur * width - 1, cury = -1;
        }
        // left
        while(curx > z[id].first){
            for(const info& cur_info : upx[curx]){
                if(cur_info.lower <= cury && cury < cur_info.upper){
                    const int c = cur_info.color;
                    if(c > 0){
                        if(--C[c - 1] == 0) cur_hash ^= h[c - 1];
                    }else{
                        if(++C[-c - 1] == 1) cur_hash ^= h[-c - 1];
                    }
                }
            }
            --curx;
        }
        // right
        while(curx < z[id].first){
            ++curx;
            for(const info& cur_info : upx[curx]){
                if(cur_info.lower <= cury && cury < cur_info.upper){
                    const int c = cur_info.color;
                    if(c > 0){
                        if(++C[c - 1] == 1) cur_hash ^= h[c - 1];
                    }else{
                        if(--C[-c - 1] == 0) cur_hash ^= h[-c - 1];
                    }
                }
            }
        }
        // up
        while(cury < z[id].second){
            ++cury;
            for(const info& cur_info : upy[cury]){
                if(cur_info.lower <= curx && curx < cur_info.upper){
                    const int c = cur_info.color;
                    if(c > 0){
                        if(++C[c - 1] == 1) cur_hash ^= h[c - 1];
                    }else{
                        if(--C[-c - 1] == 0) cur_hash ^= h[-c - 1];
                    }
                }
            }
        }
        ans[id] = cur_hash;
    }
    for(int i = 0; i < Q; ++i){
        std::cout << ans[i] << "\n";
    }
    return 0;
}
0