結果

問題 No.961 Vibrant Fillumination
ユーザー koprickykopricky
提出日時 2019-12-09 03:49:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,466 bytes
コンパイル時間 1,038 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 10,456 KB
最終ジャッジ日時 2023-09-02 00:56:18
合計ジャッジ時間 9,647 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 RE -
testcase_33 AC 2 ms
5,660 KB
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 <cmath>
#include <cstring>
#pragma GCC optimize("O3")
#pragma GCC target("avx,ssse3,sse4a")

#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;
const int WIDTH = 1000;

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<int> _index[2 * MAX_N / WIDTH + 1];
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;

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 = in(), b = in(), c = in(), d = in(), e = in();
        ++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(){
    for(int i = 0; i < Q; ++i){
        int p = in(), q = in();
        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);
    N = in();
    for(int i = 1; i <= N; ++i){
        h[i] = inll();
    }
    transform_rectangle();
    Q = in();
    transform_query();
    unsigned long long cur_hash = 0;
    int curx = -1, cury = -1;
    const int mx = (2 * N - 2) / WIDTH;
    for(int i = 0; i <= mx; ++i){
        if(_index[i].empty()) continue;
        memset(C, 0, sizeof(C)), cur_hash = 0, curx = i * WIDTH, cury = -1;
        std::sort(_index[i].begin(), _index[i].end(), [&](const int a, const int b){
            return (query[a].second == query[b].second);
        });
        for(int id : _index[i]){
            // 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){
        out(ans[i]);
    }
    return 0;
}
0