結果

問題 No.961 Vibrant Fillumination
ユーザー koprickykopricky
提出日時 2019-12-23 18:38:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 211 ms / 5,000 ms
コード長 4,643 bytes
コンパイル時間 1,875 ms
コンパイル使用メモリ 86,944 KB
実行使用メモリ 8,684 KB
最終ジャッジ日時 2023-10-23 23:41:39
合計ジャッジ時間 22,236 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 161 ms
8,540 KB
testcase_03 AC 166 ms
8,540 KB
testcase_04 AC 169 ms
8,540 KB
testcase_05 AC 171 ms
8,540 KB
testcase_06 AC 162 ms
8,540 KB
testcase_07 AC 166 ms
8,540 KB
testcase_08 AC 164 ms
8,540 KB
testcase_09 AC 165 ms
8,540 KB
testcase_10 AC 207 ms
8,540 KB
testcase_11 AC 206 ms
8,540 KB
testcase_12 AC 209 ms
8,540 KB
testcase_13 AC 208 ms
8,540 KB
testcase_14 AC 209 ms
8,540 KB
testcase_15 AC 193 ms
8,540 KB
testcase_16 AC 202 ms
8,540 KB
testcase_17 AC 192 ms
8,540 KB
testcase_18 AC 211 ms
8,540 KB
testcase_19 AC 206 ms
8,540 KB
testcase_20 AC 208 ms
8,540 KB
testcase_21 AC 194 ms
8,540 KB
testcase_22 AC 201 ms
8,540 KB
testcase_23 AC 192 ms
8,540 KB
testcase_24 AC 197 ms
8,540 KB
testcase_25 AC 208 ms
8,540 KB
testcase_26 AC 100 ms
8,540 KB
testcase_27 AC 105 ms
8,540 KB
testcase_28 AC 95 ms
8,540 KB
testcase_29 AC 107 ms
8,600 KB
testcase_30 AC 82 ms
8,680 KB
testcase_31 AC 50 ms
8,676 KB
testcase_32 AC 105 ms
8,684 KB
testcase_33 AC 2 ms
4,372 KB
testcase_34 AC 175 ms
8,540 KB
testcase_35 AC 165 ms
8,540 KB
testcase_36 AC 174 ms
8,540 KB
testcase_37 AC 176 ms
8,540 KB
testcase_38 AC 167 ms
8,540 KB
testcase_39 AC 170 ms
8,540 KB
testcase_40 AC 165 ms
8,540 KB
testcase_41 AC 171 ms
8,540 KB
testcase_42 AC 173 ms
8,540 KB
testcase_43 AC 174 ms
8,540 KB
testcase_44 AC 177 ms
8,540 KB
testcase_45 AC 176 ms
8,540 KB
testcase_46 AC 178 ms
8,540 KB
testcase_47 AC 171 ms
8,540 KB
testcase_48 AC 175 ms
8,540 KB
testcase_49 AC 179 ms
8,540 KB
権限があれば一括ダウンロードができます

ソースコード

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 = 250;

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

event 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];
    }
    // coordinate compression
    for(const std::array<int, 5>& arr : tmp){
        const int a = smx[arr[0]] + idX[arr[0]]++;
        const int b = smy[arr[1]] + idY[arr[1]]++;
        const int c = smx[arr[2]] + idX[arr[2]]++;
        const int d = smy[arr[3]] + idY[arr[3]]++;
        const int e = arr[4];
        // Upper and right borders have negative colors
        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{
            // ith query falls in (x / width)th block
            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 block_num = (2 * N - 2) / width;
    for(unsigned int block = 0; block <= block_num; ++block){
        if(_index[block].empty()) continue;
        memset(C, 0, sizeof(C)), cur_hash = 0, curx = block * width, cury = -1;
        // sort queries in ascending order for y
        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]){
            // move to the left
            while(curx > query[id].first){
                if(xborder[curx].lower <= cury && cury < xborder[curx].upper){
                    const int c = xborder[curx].color;
                    if(c > 0){
                        // go out of a rectangle
                        if(--C[c] == 0) cur_hash ^= h[c];
                    }else{
                        // go into a rectangle
                        if(++C[-c] == 1) cur_hash ^= h[-c];
                    }
                }
                --curx;
            }
            // move to the 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){
                        // go into a rectangle
                        if(++C[c] == 1) cur_hash ^= h[c];
                    }else{
                        // go out of a rectangle
                        if(--C[-c] == 0) cur_hash ^= h[-c];
                    }
                }
            }
            // move 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){
                        // go into a rectangle
                        if(++C[c] == 1) cur_hash ^= h[c];
                    }else{
                        // go out of a rectangle
                        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