結果

問題 No.961 Vibrant Fillumination
ユーザー PachicobuePachicobue
提出日時 2019-10-20 20:22:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,591 bytes
コンパイル時間 2,811 ms
コンパイル使用メモリ 210,568 KB
実行使用メモリ 8,344 KB
最終ジャッジ日時 2023-08-30 20:40:52
合計ジャッジ時間 21,648 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 287 ms
7,980 KB
testcase_03 AC 292 ms
8,068 KB
testcase_04 AC 300 ms
7,992 KB
testcase_05 AC 296 ms
8,116 KB
testcase_06 AC 284 ms
7,976 KB
testcase_07 AC 295 ms
8,100 KB
testcase_08 AC 292 ms
8,136 KB
testcase_09 AC 294 ms
8,072 KB
testcase_10 AC 415 ms
8,040 KB
testcase_11 AC 411 ms
8,136 KB
testcase_12 AC 419 ms
7,976 KB
testcase_13 AC 404 ms
8,068 KB
testcase_14 AC 424 ms
8,096 KB
testcase_15 AC 364 ms
8,136 KB
testcase_16 AC 402 ms
8,252 KB
testcase_17 AC 366 ms
8,136 KB
testcase_18 AC 411 ms
8,040 KB
testcase_19 AC 407 ms
8,004 KB
testcase_20 AC 407 ms
8,092 KB
testcase_21 AC 365 ms
8,136 KB
testcase_22 AC 372 ms
7,988 KB
testcase_23 AC 364 ms
8,044 KB
testcase_24 AC 387 ms
8,124 KB
testcase_25 AC 404 ms
8,264 KB
testcase_26 AC 160 ms
8,140 KB
testcase_27 AC 138 ms
8,040 KB
testcase_28 AC 167 ms
8,128 KB
testcase_29 AC 158 ms
8,052 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 320 ms
8,104 KB
testcase_35 AC 294 ms
8,056 KB
testcase_36 AC 312 ms
8,056 KB
testcase_37 AC 316 ms
7,992 KB
testcase_38 AC 300 ms
7,992 KB
testcase_39 AC 298 ms
8,072 KB
testcase_40 AC 298 ms
8,076 KB
testcase_41 AC 298 ms
8,072 KB
testcase_42 AC 308 ms
8,264 KB
testcase_43 AC 316 ms
7,988 KB
testcase_44 AC 322 ms
8,004 KB
testcase_45 AC 310 ms
8,104 KB
testcase_46 AC 318 ms
8,076 KB
testcase_47 AC 307 ms
8,068 KB
testcase_48 AC 317 ms
8,204 KB
testcase_49 AC 320 ms
8,004 KB
権限があれば一括ダウンロードができます

ソースコード

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);
    }
    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 = 300;
    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] ? (bi % 2 == 0 ? 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) { 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])]; };
    for (const usize i : inds) {
        const usize nx = p[i], ny = q[i];  // 次のクエリ点
        for (; x < nx; x++) {
            if (von(x + 1, y)) { add_del_film(lr[x + 1]); }
        }
        for (; x > nx; x--) {
            if (von(x, y)) { add_del_film(-lr[x]); }
        }
        for (; y < ny; y++) {
            if (hon(x, y + 1)) { add_del_film(du[y + 1]); }
        }
        for (; y > ny; y--) {
            if (hon(x, y)) { add_del_film(-du[y]); }
        }
        answer[i] = hash;
    }

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

    return 0;
}
0