結果

問題 No.961 Vibrant Fillumination
ユーザー PachicobuePachicobue
提出日時 2019-12-08 23:55:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,008 ms / 5,000 ms
コード長 5,168 bytes
コンパイル時間 4,250 ms
コンパイル使用メモリ 224,668 KB
実行使用メモリ 32,364 KB
最終ジャッジ日時 2023-08-30 22:24:49
合計ジャッジ時間 49,862 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,724 KB
testcase_01 AC 3 ms
4,652 KB
testcase_02 AC 802 ms
31,696 KB
testcase_03 AC 834 ms
32,136 KB
testcase_04 AC 853 ms
31,748 KB
testcase_05 AC 836 ms
31,616 KB
testcase_06 AC 810 ms
31,544 KB
testcase_07 AC 830 ms
31,544 KB
testcase_08 AC 817 ms
31,700 KB
testcase_09 AC 821 ms
31,700 KB
testcase_10 AC 997 ms
32,144 KB
testcase_11 AC 985 ms
32,140 KB
testcase_12 AC 989 ms
32,132 KB
testcase_13 AC 997 ms
32,148 KB
testcase_14 AC 1,008 ms
32,224 KB
testcase_15 AC 988 ms
32,204 KB
testcase_16 AC 986 ms
32,084 KB
testcase_17 AC 950 ms
32,140 KB
testcase_18 AC 997 ms
32,136 KB
testcase_19 AC 981 ms
32,144 KB
testcase_20 AC 992 ms
32,272 KB
testcase_21 AC 943 ms
32,076 KB
testcase_22 AC 971 ms
32,268 KB
testcase_23 AC 978 ms
32,084 KB
testcase_24 AC 963 ms
32,088 KB
testcase_25 AC 990 ms
32,324 KB
testcase_26 AC 696 ms
32,144 KB
testcase_27 AC 497 ms
31,152 KB
testcase_28 AC 702 ms
32,264 KB
testcase_29 AC 569 ms
32,004 KB
testcase_30 AC 331 ms
30,232 KB
testcase_31 AC 266 ms
30,224 KB
testcase_32 AC 482 ms
30,372 KB
testcase_33 AC 3 ms
4,604 KB
testcase_34 AC 887 ms
32,152 KB
testcase_35 AC 864 ms
32,076 KB
testcase_36 AC 893 ms
32,148 KB
testcase_37 AC 906 ms
32,080 KB
testcase_38 AC 860 ms
32,220 KB
testcase_39 AC 884 ms
32,252 KB
testcase_40 AC 857 ms
32,080 KB
testcase_41 AC 877 ms
32,072 KB
testcase_42 AC 865 ms
32,136 KB
testcase_43 AC 877 ms
32,080 KB
testcase_44 AC 893 ms
32,364 KB
testcase_45 AC 906 ms
32,224 KB
testcase_46 AC 887 ms
32,268 KB
testcase_47 AC 894 ms
32,084 KB
testcase_48 AC 890 ms
32,140 KB
testcase_49 AC 887 ms
32,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
class stopwatch
{
public:
    stopwatch() : start{std::chrono::system_clock::now()}, rap_point{start} {}
    template<typename Duration = std::chrono::milliseconds>
    int64_t rap()
    {
        const auto now   = std::chrono::system_clock::now();
        const auto cnt   = std::chrono::duration_cast<Duration>(now - rap_point).count();
        return rap_point = now, cnt;
    }
    template<typename Duration = std::chrono::milliseconds>
    int64_t total()
    {
        const auto now = std::chrono::system_clock::now();
        const auto cnt = std::chrono::duration_cast<Duration>(now - start).count();
        return cnt;
    }

private:
    std::chrono::system_clock::time_point start;
    std::chrono::system_clock::time_point rap_point;
};
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]; }

    constexpr ull NUM = 100000;                                           // eps用(i/NUM を足してdistinctにする)
    std::vector<ull> eps_x(NUM + 1, 0), eps_y(NUM + 1, 0);                // eps用(i/NUM を足してdistinctにする)
    std::vector<ull> A(N + 1, 0), B(N + 1, 0), C(N + 1, 0), D(N + 1, 0);  // フィルム座標(座圧前)
    std::vector<ull> e(N + 1, 0);                                         // フィルム色
    std::vector<ull> unzip_x{0LL}, unzip_y{0LL};
    std::map<ull, usize> zip_x, zip_y;
    for (usize i = 1; i <= N; i++) {
        std::cin >> A[i] >> B[i] >> C[i] >> D[i] >> e[i];
        A[i]++, B[i]++, C[i]++, D[i]++;
        A[i] = A[i] * NUM + (eps_x[A[i]]++);
        B[i] = B[i] * NUM + (eps_y[B[i]]++);
        C[i] = C[i] * NUM + (eps_x[C[i]]++);
        D[i] = D[i] * NUM + (eps_y[D[i]]++);
        unzip_x.push_back(A[i]), unzip_y.push_back(B[i]), unzip_x.push_back(C[i]), unzip_y.push_back(D[i]);
    }
    usize QN;
    std::cin >> QN;
    std::vector<usize> P(QN), Q(QN);  // クエリ座標(座圧前)
    for (usize i = 0; i < QN; i++) {
        std::cin >> P[i] >> Q[i];
        P[i]++, Q[i]++;
        P[i] = P[i] * NUM + (eps_x[P[i]]);
        Q[i] = Q[i] * NUM + (eps_y[Q[i]]);
        unzip_x.push_back(P[i]), unzip_y.push_back(Q[i]);
    }
    std::sort(unzip_x.begin(), unzip_x.end());
    std::sort(unzip_y.begin(), unzip_y.end());
    unzip_x.erase(std::unique(unzip_x.begin(), unzip_x.end()), unzip_x.end());
    unzip_y.erase(std::unique(unzip_y.begin(), unzip_y.end()), unzip_y.end());
    const usize X = unzip_x.size();
    const usize Y = unzip_y.size();
    for (usize i = 0; i < X; i++) { zip_x[unzip_x[i]] = i; }
    for (usize i = 0; i < Y; i++) { zip_y[unzip_y[i]] = i; }

    std::vector<usize> a(N + 1, 0), b(N + 1, 0), c(N + 1, X), d(N + 1, Y);  // フィルム座標(座圧後)
    std::vector<usize> p(QN), q(QN);                                        // クエリ座標(座圧後)
    std::vector<int> lr(X + 1, 0), du(Y + 1, 0);                            // 左右矢印,上下矢印
    for (usize i = 1; i <= N; i++) {
        a[i] = zip_x[A[i]], b[i] = zip_y[B[i]], c[i] = zip_x[C[i]], d[i] = zip_y[D[i]];
        lr[a[i]] = du[b[i]] = int(i), lr[c[i]] = du[d[i]] = -int(i);
    }
    for (usize i = 0; i < QN; i++) { p[i] = zip_x[P[i]], q[i] = zip_y[Q[i]]; }

    constexpr usize BS = 800;
    std::vector<usize> inds(QN);
    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(QN);
    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 < QN; i++) { std::cout << answer[i] << "\n"; }
    return 0;
}
0