結果

問題 No.961 Vibrant Fillumination
ユーザー PachicobuePachicobue
提出日時 2019-12-23 19:28:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 574 ms / 5,000 ms
コード長 4,983 bytes
コンパイル時間 3,160 ms
コンパイル使用メモリ 230,788 KB
実行使用メモリ 24,640 KB
最終ジャッジ日時 2023-10-23 23:43:46
合計ジャッジ時間 33,589 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,800 KB
testcase_01 AC 3 ms
4,800 KB
testcase_02 AC 484 ms
24,640 KB
testcase_03 AC 492 ms
24,640 KB
testcase_04 AC 481 ms
24,640 KB
testcase_05 AC 496 ms
24,640 KB
testcase_06 AC 475 ms
24,640 KB
testcase_07 AC 503 ms
24,640 KB
testcase_08 AC 487 ms
24,640 KB
testcase_09 AC 487 ms
24,640 KB
testcase_10 AC 565 ms
24,640 KB
testcase_11 AC 565 ms
24,640 KB
testcase_12 AC 567 ms
24,640 KB
testcase_13 AC 558 ms
24,640 KB
testcase_14 AC 574 ms
24,640 KB
testcase_15 AC 547 ms
24,640 KB
testcase_16 AC 566 ms
24,640 KB
testcase_17 AC 535 ms
24,640 KB
testcase_18 AC 556 ms
24,640 KB
testcase_19 AC 562 ms
24,640 KB
testcase_20 AC 548 ms
24,640 KB
testcase_21 AC 541 ms
24,640 KB
testcase_22 AC 546 ms
24,640 KB
testcase_23 AC 544 ms
24,640 KB
testcase_24 AC 558 ms
24,640 KB
testcase_25 AC 563 ms
24,640 KB
testcase_26 AC 367 ms
24,640 KB
testcase_27 AC 365 ms
24,640 KB
testcase_28 AC 388 ms
24,640 KB
testcase_29 AC 407 ms
24,640 KB
testcase_30 AC 272 ms
24,640 KB
testcase_31 AC 236 ms
24,640 KB
testcase_32 AC 346 ms
24,640 KB
testcase_33 AC 3 ms
4,800 KB
testcase_34 AC 505 ms
24,640 KB
testcase_35 AC 544 ms
24,640 KB
testcase_36 AC 502 ms
24,640 KB
testcase_37 AC 503 ms
24,640 KB
testcase_38 AC 506 ms
24,640 KB
testcase_39 AC 508 ms
24,640 KB
testcase_40 AC 502 ms
24,640 KB
testcase_41 AC 504 ms
24,640 KB
testcase_42 AC 500 ms
24,640 KB
testcase_43 AC 507 ms
24,640 KB
testcase_44 AC 511 ms
24,640 KB
testcase_45 AC 488 ms
24,640 KB
testcase_46 AC 495 ms
24,640 KB
testcase_47 AC 501 ms
24,640 KB
testcase_48 AC 508 ms
24,640 KB
testcase_49 AC 517 ms
24,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll  = long long;
using ull = unsigned long long;
int main()
{
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false);
    int N;
    std::cin >> N;
    assert(1 <= N and N <= 50000);
    std::vector<ull> h(N + 1, 0ULL);  // ハッシュ値
    for (int i = 1; i <= N; i++) {
        ll h_;
        std::cin >> h_;
        assert(0 <= h_ and h_ < (1LL << 60));
        h[i] = (ull)h_;
    }

    constexpr ll NUM = 100000;                                           // eps用(i/NUM を足してdistinctにする)
    std::vector<ll> eps_x(NUM + 1, 0), eps_y(NUM + 1, 0);                // eps用(i/NUM を足してdistinctにする)
    std::vector<ll> A(N + 1, 0), B(N + 1, 0), C(N + 1, 0), D(N + 1, 0);  // フィルム座標(座圧前)
    std::vector<ll> e(N + 1, 0);                                         // フィルム色
    std::vector<ll> unzip_x{0LL}, unzip_y{0LL};
    std::map<ll, int> zip_x, zip_y;
    for (int i = 1; i <= N; i++) {
        std::cin >> A[i] >> B[i] >> C[i] >> D[i] >> e[i];
        assert(0 <= A[i] and A[i] < 2 * N);
        assert(0 <= B[i] and B[i] < 2 * N);
        assert(0 <= C[i] and C[i] < 2 * N);
        assert(0 <= D[i] and D[i] < 2 * N);
        assert(A[i] < C[i]);
        assert(B[i] < D[i]);
        assert(1 <= e[i] and e[i] <= N);
        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]);
    }
    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 int X = unzip_x.size();
    const int Y = unzip_y.size();
    for (int i = 0; i < X; i++) { zip_x[unzip_x[i]] = i; }
    for (int i = 0; i < Y; i++) { zip_y[unzip_y[i]] = i; }
    int QN;
    std::cin >> QN;
    assert(1 <= QN and QN <= 50000);
    std::vector<ll> P(QN), Q(QN);  // クエリ座標(座圧前)
    for (int i = 0; i < QN; i++) {
        std::cin >> P[i] >> Q[i];
        assert(0 <= P[i] and P[i] < 2 * N);
        assert(0 <= Q[i] and Q[i] < 2 * N);
        P[i]++, Q[i]++;
        P[i] = P[i] * NUM + (eps_x[P[i]]);
        Q[i] = Q[i] * NUM + (eps_y[Q[i]]);
        P[i] = *std::prev(std::upper_bound(unzip_x.begin(), unzip_x.end(), P[i]));
        Q[i] = *std::prev(std::upper_bound(unzip_y.begin(), unzip_y.end(), Q[i]));
    }

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

    const int BS = 1000;  // バケットサイズ
    std::vector<int> inds(QN);
    std::iota(inds.begin(), inds.end(), 0UL);
    std::sort(inds.begin(), inds.end(), [&](const int i, const int j) {
        const int 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<int> color_cnt(N + 1, 0);
    ull hash      = 0;
    auto add_film = [&](const int i) {  // フィルムiを追加
        const int c = e[i];
        if (color_cnt[c]++ == 0) { hash ^= h[c]; }
    };
    auto del_film = [&](const int i) {  // フィルムiを削除
        const int c = e[i];
        if (--color_cnt[c] == 0) { hash ^= h[c]; }
    };
    auto add_del_film = [&](const int i) {
        if (i > 0) { add_film(int(i)); }
        if (i < 0) { del_film(int(-i)); }
    };

    std::vector<ull> answer(QN);
    int x = 0, y = 0;
    auto von = [&](const int x, const int y) { return b[(int)std::abs(lr[x])] <= y and y < d[(int)std::abs(lr[x])]; };
    auto hon = [&](const int x, const int y) { return a[(int)std::abs(du[y])] <= x and x < c[(int)std::abs(du[y])]; };
    for (const int i : inds) {
        const int 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 (int i = 0; i < QN; i++) { std::cout << answer[i] << "\n"; }
    return 0;
}
0