結果

問題 No.961 Vibrant Fillumination
ユーザー koprickykopricky
提出日時 2019-12-09 03:33:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 227 ms / 5,000 ms
コード長 4,401 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 86,284 KB
実行使用メモリ 10,352 KB
最終ジャッジ日時 2023-09-02 00:34:41
合計ジャッジ時間 14,417 ms
ジャッジサーバーID
(参考情報)
judge16 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,684 KB
testcase_01 AC 2 ms
5,764 KB
testcase_02 AC 181 ms
10,160 KB
testcase_03 AC 182 ms
10,068 KB
testcase_04 AC 182 ms
10,128 KB
testcase_05 AC 185 ms
10,160 KB
testcase_06 AC 178 ms
10,160 KB
testcase_07 AC 183 ms
10,072 KB
testcase_08 AC 182 ms
10,068 KB
testcase_09 AC 183 ms
10,164 KB
testcase_10 AC 223 ms
10,132 KB
testcase_11 AC 223 ms
10,220 KB
testcase_12 AC 226 ms
10,352 KB
testcase_13 AC 221 ms
10,112 KB
testcase_14 AC 227 ms
10,068 KB
testcase_15 AC 206 ms
10,144 KB
testcase_16 AC 221 ms
10,112 KB
testcase_17 AC 206 ms
10,300 KB
testcase_18 AC 226 ms
10,068 KB
testcase_19 AC 223 ms
10,064 KB
testcase_20 AC 224 ms
10,072 KB
testcase_21 AC 208 ms
10,112 KB
testcase_22 AC 211 ms
10,220 KB
testcase_23 AC 208 ms
10,220 KB
testcase_24 AC 216 ms
10,156 KB
testcase_25 AC 224 ms
10,060 KB
testcase_26 AC 116 ms
10,116 KB
testcase_27 AC 120 ms
10,064 KB
testcase_28 AC 117 ms
10,120 KB
testcase_29 AC 122 ms
10,164 KB
testcase_30 AC 93 ms
10,196 KB
testcase_31 AC 50 ms
10,296 KB
testcase_32 AC 111 ms
10,300 KB
testcase_33 AC 2 ms
5,640 KB
testcase_34 AC 191 ms
10,156 KB
testcase_35 AC 181 ms
10,172 KB
testcase_36 AC 188 ms
10,128 KB
testcase_37 AC 193 ms
10,176 KB
testcase_38 AC 184 ms
10,156 KB
testcase_39 AC 186 ms
10,068 KB
testcase_40 AC 183 ms
10,068 KB
testcase_41 AC 186 ms
10,160 KB
testcase_42 AC 190 ms
10,056 KB
testcase_43 AC 193 ms
10,160 KB
testcase_44 AC 193 ms
10,116 KB
testcase_45 AC 188 ms
10,120 KB
testcase_46 AC 191 ms
10,184 KB
testcase_47 AC 189 ms
10,164 KB
testcase_48 AC 192 ms
10,164 KB
testcase_49 AC 195 ms
10,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#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');
}

const int MAX_N = 50003;
const int MAX_Q = 50003;

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::pair<int, int> query[MAX_Q];
unsigned long long h[MAX_N], ans[MAX_Q];
int smx[2 * MAX_N], smy[2 * MAX_N], C[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;
        ++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::vector<int>& 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(std::vector<int>& index){
    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.push_back(i);
        }
    }
}

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;
    std::vector<int> index;
    transform_query(index);
    const int width = 2 * ceil(sqrt(N));
    std::sort(index.begin(), index.end(), [&](const int a, const int b){
        const int u = query[a].first / width, v = query[b].first / width;
        return (u == v) ? (query[a].second < query[b].second) : (u < v);
    });
    unsigned long long cur_hash = 0;
    int prv = -1, curx = -1, cury = -1;
    for(const int id : index){
        const int cur = query[id].first / width;
        if(prv != cur){
            // enter new block
            memset(C, 0, sizeof(C)), cur_hash = 0, prv = cur, curx = cur * width - 1, cury = -1;
        }
        // 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