結果

問題 No.961 Vibrant Fillumination
ユーザー PachicobuePachicobue
提出日時 2019-12-08 22:48:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,066 bytes
コンパイル時間 4,863 ms
コンパイル使用メモリ 211,756 KB
実行使用メモリ 24,832 KB
最終ジャッジ日時 2023-09-01 23:16:59
合計ジャッジ時間 80,003 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2,400 ms
18,432 KB
testcase_03 AC 2,121 ms
18,376 KB
testcase_04 AC 1,859 ms
18,424 KB
testcase_05 AC 2,015 ms
18,324 KB
testcase_06 AC 2,463 ms
18,304 KB
testcase_07 AC 2,476 ms
18,264 KB
testcase_08 AC 2,425 ms
18,432 KB
testcase_09 AC 2,446 ms
18,252 KB
testcase_10 AC 2,707 ms
18,372 KB
testcase_11 AC 2,662 ms
18,312 KB
testcase_12 AC 2,706 ms
18,368 KB
testcase_13 AC 2,473 ms
18,376 KB
testcase_14 AC 2,723 ms
18,424 KB
testcase_15 AC 2,256 ms
18,364 KB
testcase_16 AC 2,765 ms
18,372 KB
testcase_17 AC 2,150 ms
18,428 KB
testcase_18 AC 2,747 ms
18,292 KB
testcase_19 AC 2,543 ms
18,372 KB
testcase_20 AC 2,587 ms
18,432 KB
testcase_21 AC 2,353 ms
18,368 KB
testcase_22 AC 2,251 ms
18,380 KB
testcase_23 AC 2,192 ms
18,320 KB
testcase_24 AC 2,426 ms
18,372 KB
testcase_25 AC 2,271 ms
18,444 KB
testcase_26 AC 1,862 ms
18,268 KB
testcase_27 AC 1,669 ms
18,492 KB
testcase_28 AC 2,418 ms
18,360 KB
testcase_29 AC 2,295 ms
18,432 KB
testcase_30 TLE -
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<std::vector<int>> lr(L + 1), du(L + 1);
    //    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]].push_back(int(i));
        du[++b[i]].push_back(int(i));
        lr[++c[i]].push_back(-int(i));
        du[++d[i]].push_back(-int(i));
    }
    usize Q;
    std::cin >> Q;
    std::vector<usize> p(Q), q(Q);
    for (usize i = 0; i < Q; i++) { std::cin >> p[i] >> q[i], p[i]++, q[i]++; }

    constexpr usize BS = 800;
    std::vector<usize> inds(Q);
    std::iota(inds.begin(), inds.end(), 0UL);
    std::sort(inds.begin(), inds.end(), [&](const usize i, const usize j) {
        const usize bi = p[i] / BS, bj = p[j] / BS;
        return bi != bj ? bi < bj : q[i] != q[j] ? q[i] < q[j] : p[i] < p[j];
    });

    std::vector<usize> color_cnt(N + 1, 0);
    ull hash      = 0;
    auto add_film = [&](const usize i) {  // フィルムiを追加
        const usize c = e[i];
        if (color_cnt[c]++ == 0) { hash ^= h[c]; }
    };
    auto del_film = [&](const usize i) {  // フィルム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)); }
    };

    std::vector<ull> answer(Q);
    usize x = 0, y = 0;
    auto von = [&](const usize x, const usize y) {
        std::vector<int> ans;
        for (const int f : lr[x]) {
            const usize yl = b[(usize)std::abs(f)], yu = d[(usize)std::abs(f)];
            if (yl <= y and y < yu) { ans.push_back(f); }
        }
        return ans;
    };
    auto hon = [&](const usize x, const usize y) {
        std::vector<int> ans;
        for (const int f : du[y]) {
            const usize xl = a[(usize)std::abs(f)], xu = c[(usize)std::abs(f)];
            if (xl <= x and x < xu) { ans.push_back(f); }
        }
        return ans;
    };
    for (const usize i : inds) {
        const usize nx = p[i], ny = q[i];  // 次のクエリ点
        for (; x < nx; x++) {
            for (const int f : von(x + 1, y)) { add_del_film(f); }
        }
        for (; x > nx; x--) {
            for (const int f : von(x, y)) { add_del_film(-f); }
        }
        for (; y < ny; y++) {
            for (const int f : hon(x, y + 1)) { add_del_film(f); }
        }
        for (; y > ny; y--) {
            for (const int f : hon(x, y)) { add_del_film(-f); }
        }
        answer[i] = hash;
    }

    for (usize i = 0; i < Q; i++) { std::cout << answer[i] << "\n"; }

    return 0;
}
0