結果

問題 No.961 Vibrant Fillumination
ユーザー PachicobuePachicobue
提出日時 2019-10-21 15:48:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,382 bytes
コンパイル時間 2,531 ms
コンパイル使用メモリ 217,068 KB
実行使用メモリ 814,468 KB
最終ジャッジ日時 2023-09-15 14:58:39
合計ジャッジ時間 7,200 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using ull   = unsigned long long;
using usize = std::size_t;
int main()
{
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false);
    usize N;
    std::cin >> N;
    std::vector<ull> h(N + 1, 0ULL);
    for (usize i = 1; i <= N; i++) { std::cin >> h[i]; }

    const usize L = 2 * N;
    std::vector<usize> a(N + 1, 0), b(N + 1, 0), c(N + 1, L), d(N + 1, L), e(N + 1, 0);
    std::vector<int> lr(L + 1, 0), du(L + 1, 0);
    for (usize i = 1; i <= N; i++) {
        std::cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i];
        lr[++a[i]] = du[++b[i]] = int(i), lr[++c[i]] = du[++d[i]] = -int(i);
    }
    constexpr usize BS = 2000;
    const usize BN     = (N + BS - 1) / BS;
    std::vector<std::vector<ull>> hashs(BN, std::vector<ull>(BN, 0ULL));
    std::vector<std::vector<std::vector<usize>>> cs(BN, std::vector<std::vector<usize>>(BN));
    std::vector<std::vector<std::vector<usize>>> cnt(BN, std::vector<std::vector<usize>>(BN));
    for (usize x = 0; x < N; x++) {
        for (usize y = 0; y < N; y++) {
            const int xind = lr[x], yind = du[y];
            if (xind != 0) { cs[x / BS][y / BS].push_back(e[(usize)std::abs(xind)]); }
            if (yind != 0) { cs[x / BS][y / BS].push_back(e[(usize)std::abs(yind)]); }
        }
    }
    for (usize i = 0; i < BN; i++) {
        for (usize j = 0; j < BN; j++) {
            std::sort(cs[i][j].begin(), cs[i][j].end());
            cs[i][j].erase(std::unique(cs[i][j].begin(), cs[i][j].end()), cs[i][j].end());
        }
    }

    std::vector<usize> color_cnt(N + 1, 0);
    ull hash      = 0;
    auto von      = [&](const usize x, const usize y) { return b[(usize)std::abs(lr[x])] <= y and y < d[(usize)std::abs(lr[x])]; };
    auto hon      = [&](const usize x, const usize y) { return a[(usize)std::abs(du[y])] <= x and x < c[(usize)std::abs(du[y])]; };
    auto add_film = [&](const usize i) {
        const usize c = e[i];
        if (color_cnt[c]++ == 0) { hash ^= h[c]; }
    };
    auto del_film = [&](const usize i) {
        const usize c = e[i];
        if (--color_cnt[c] == 0) { hash ^= h[c]; }
    };
    auto add_del_film = [&](const int i) {
        if (i > 0) { add_film(usize(i)); }
        if (i < 0) { del_film(usize(-i)); }
    };
    for (usize i = 0; i < BN; i++) {
        hash    = 0, std::fill(color_cnt.begin(), color_cnt.end(), 0);
        usize x = i * BS, y = 0;
        for (usize j = 0; j < BN; j++) {
            const usize ny = std::min(N, (j + 1) * BS);
            for (; y < ny; y++) {
                if (hon(x, y + 1)) { add_del_film(du[y + 1]); }
            }
            hashs[i][j] = hash;
            for (const usize ci : cs[i][j]) { cnt[i][j].push_back(color_cnt[ci]); }
        }
    }
    usize Q;
    std::cin >> Q;
    for (usize i = 0, p, q; i < Q; i++) {
        std::cin >> p >> q, p++, q++;
        const usize xi = p / BS, yi = q / BS;
        usize x = xi * BS, y = yi * BS;
        hash = hashs[xi][yi];
        for (const usize ci : cs[xi][yi]) { color_cnt[ci] = cnt[xi][yi][(usize)(std::lower_bound(cs[xi][yi].begin(), cs[xi][yi].end(), ci) - cs[xi][yi].begin())]; }
        for (; x < p; x++) {
            if (von(x + 1, y)) { add_del_film(lr[x + 1]); }
        }
        for (; y < q; y++) {
            if (hon(x, y + 1)) { add_del_film(du[y + 1]); }
        }
        std::cout << hash << "\n";
    }

    return 0;
}
0