結果

問題 No.961 Vibrant Fillumination
ユーザー koprickykopricky
提出日時 2019-10-20 21:11:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,673 bytes
コンパイル時間 1,378 ms
コンパイル使用メモリ 86,080 KB
実行使用メモリ 7,220 KB
最終ジャッジ日時 2023-09-15 14:46:07
合計ジャッジ時間 10,822 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MAX_N = 50000;

#define getchar getchar_unlocked
#define putchar putchar_unlocked

inline int in() {
    int n = 0; short c;
    while ((c = getchar()) >= '0') n = n * 10 + c - '0';
    return n;
}

inline unsigned long long inll() {
    unsigned long long n = 0; short c;
    while ((c = getchar()) >= '0') n = n * 10 + c - '0';
    return n;
}

inline void out(unsigned long long n) {
    short res[20], i = 0;
    do { res[i++] = n % 10, n /= 10; } while (n);
    while (i) putchar(res[--i] + '0');
    putchar('\n');
}

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){}
};

info upx[2 * MAX_N], upy[2 * MAX_N];

int main()
{
    // std::cin.tie(0);
    // std::ios::sync_with_stdio(false);
    int N;
    // std::cin >> N;
    N = in();
    std::vector<unsigned long long> h(N);
    for(int i = 0; i < N; ++i){
        // std::cin >> h[i];
        h[i] = inll();
    }
    for(int i = 0; i < N; ++i){
        int a, b, c, d, e;
        // std::cin >> a >> b >> c >> d >> e;
        a = in(), b = in(), c = in(), d = in(), e = in();
        upx[a] = {b, d, e}, upx[c] = {b, d, -e}, upy[b] = {a, c, e}, upy[d] = {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;
        p = in(), q = in();
        z[i] = {p, q};
    }
    const int width = 1000;
    // const int width = ceil(sqrt(2 * 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);
    std::vector<int> C(N, 0);
    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){
            fill(C.begin(), C.end(), 0), cur_hash = 0, prv = cur, curx = cur * width - 1, cury = -1;
        }
        // left
        while(curx > z[id].first){
            if(upx[curx].lower <= cury && cury < upx[curx].upper){
                const int c = upx[curx].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;
            if(upx[curx].lower <= cury && cury < upx[curx].upper){
                const int c = upx[curx].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;
            if(upy[cury].lower <= curx && curx < upy[cury].upper){
                const int c = upy[cury].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";
        out(ans[i]);
    }
    return 0;
}
0