結果

問題 No.961 Vibrant Fillumination
ユーザー koprickykopricky
提出日時 2019-12-09 04:11:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 4,102 bytes
コンパイル時間 2,762 ms
コンパイル使用メモリ 85,736 KB
実行使用メモリ 8,560 KB
最終ジャッジ日時 2023-09-02 07:48:35
合計ジャッジ時間 16,290 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

const int MAX_N = 50003;
const int MAX_Q = 50003;
const int MAX_BLOCK = 120;

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];
std::vector<unsigned int> _index[MAX_BLOCK];
std::pair<int, int> query[MAX_Q];
unsigned long long h[MAX_N], ans[MAX_Q];
unsigned int smx[2 * MAX_N], smy[2 * MAX_N], C[MAX_N];
int N, Q, width;

void transform_rectangle(){
    std::vector<std::array<int, 5> > 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;
        ++smx[a + 1], ++smx[c + 1], ++smy[b + 1], ++smy[d + 1];
        tmp[i] = {a, b, c, d, e};
    }
    for(int i = 0; i < 2 * N; ++i){
        smx[i + 1] += smx[i], smy[i + 1] += smy[i];
    }
    for(const std::array<int, 5>& in : tmp){
        const int a = smx[in[0]] + idX[in[0]]++;
        const int b = smy[in[1]] + idY[in[1]]++;
        const int c = smx[in[2]] + idX[in[2]]++;
        const int d = smy[in[3]] + 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 transform_query(){
    for(int i = 0; i < Q; ++i){
        int p, q;
        std::cin >> p >> q;
        const int x = smx[p + 1] - 1;
        const int y = smy[q + 1] - 1;
        if(x < 0 || x >= 2 * N - 1 || y < 0 || y >= 2 * N - 1){
            // out of range
            ans[i] = 0ULL;
        }else{
            query[i] = {x, y}, _index[x / width].push_back(i);
        }
    }
}

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cin >> N;
    width = 2 * ceil(sqrt(N));
    for(int i = 1; i <= N; ++i){
        std::cin >> h[i];
    }
    transform_rectangle();
    std::cin >> Q;
    transform_query();
    unsigned long long cur_hash = 0;
    int curx = -1, cury = -1;
    const unsigned int mx = (2 * N - 2) / width;
    for(unsigned int block = 0; block <= mx; ++block){
        if(_index[block].empty()) continue;
        memset(C, 0, sizeof(C)), cur_hash = 0, curx = block * width, cury = -1;
        std::sort(_index[block].begin(), _index[block].end(), 
            [&](const unsigned int a, const unsigned int b){
                return (query[a].second < query[b].second);
        });
        for(const unsigned int id : _index[block]){
            // left
            while(curx > query[id].first){
                if(xborder[curx].lower <= cury && cury < xborder[curx].upper){
                    const int c = xborder[curx].color;
                    if(c > 0){
                        if(--C[c] == 0) cur_hash ^= h[c];
                    }else{
                        if(++C[-c] == 1) cur_hash ^= h[-c];
                    }
                }
                --curx;
            }
            // right
            while(curx < query[id].first){
                ++curx;
                if(xborder[curx].lower <= cury && cury < xborder[curx].upper){
                    const int c = xborder[curx].color;
                    if(c > 0){
                        if(++C[c] == 1) cur_hash ^= h[c];
                    }else{
                        if(--C[-c] == 0) cur_hash ^= h[-c];
                    }
                }
            }
            // up
            while(cury < query[id].second){
                ++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];
                    }
                }
            }
            ans[id] = cur_hash;
        }
    }
    for(int i = 0; i < Q; ++i){
        std::cout << ans[i] << "\n";
    }
    return 0;
}
0