結果

問題 No.961 Vibrant Fillumination
ユーザー pekempeypekempey
提出日時 2019-12-24 12:40:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 683 ms / 5,000 ms
コード長 3,387 bytes
コンパイル時間 2,744 ms
コンパイル使用メモリ 192,208 KB
実行使用メモリ 9,236 KB
最終ジャッジ日時 2023-10-24 00:08:51
合計ジャッジ時間 34,131 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 566 ms
9,236 KB
testcase_03 AC 595 ms
8,444 KB
testcase_04 AC 552 ms
9,236 KB
testcase_05 AC 559 ms
8,444 KB
testcase_06 AC 566 ms
9,236 KB
testcase_07 AC 553 ms
9,236 KB
testcase_08 AC 559 ms
9,236 KB
testcase_09 AC 564 ms
9,236 KB
testcase_10 AC 661 ms
9,236 KB
testcase_11 AC 678 ms
9,236 KB
testcase_12 AC 662 ms
9,236 KB
testcase_13 AC 645 ms
8,972 KB
testcase_14 AC 683 ms
9,236 KB
testcase_15 AC 634 ms
8,444 KB
testcase_16 AC 669 ms
9,236 KB
testcase_17 AC 638 ms
8,972 KB
testcase_18 AC 666 ms
9,236 KB
testcase_19 AC 653 ms
8,972 KB
testcase_20 AC 660 ms
9,236 KB
testcase_21 AC 621 ms
9,236 KB
testcase_22 AC 633 ms
9,236 KB
testcase_23 AC 617 ms
8,444 KB
testcase_24 AC 643 ms
8,444 KB
testcase_25 AC 655 ms
9,236 KB
testcase_26 AC 519 ms
8,444 KB
testcase_27 AC 444 ms
8,444 KB
testcase_28 AC 557 ms
9,236 KB
testcase_29 AC 575 ms
9,236 KB
testcase_30 AC 335 ms
8,444 KB
testcase_31 AC 417 ms
9,236 KB
testcase_32 AC 286 ms
9,236 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 609 ms
9,236 KB
testcase_35 AC 601 ms
9,236 KB
testcase_36 AC 598 ms
9,236 KB
testcase_37 AC 597 ms
8,972 KB
testcase_38 AC 591 ms
9,236 KB
testcase_39 AC 588 ms
8,444 KB
testcase_40 AC 595 ms
9,236 KB
testcase_41 AC 590 ms
8,972 KB
testcase_42 AC 594 ms
9,236 KB
testcase_43 AC 593 ms
8,972 KB
testcase_44 AC 596 ms
9,236 KB
testcase_45 AC 584 ms
9,236 KB
testcase_46 AC 595 ms
9,236 KB
testcase_47 AC 586 ms
8,444 KB
testcase_48 AC 598 ms
8,444 KB
testcase_49 AC 597 ms
9,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<ll> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  vector<int> A(N), B(N), C(N), D(N), E(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i];
    E[i]--;
  }
  int Q; cin >> Q;
  vector<int> X(Q), Y(Q);
  for (int i = 0; i < Q; i++) {
    cin >> X[i] >> Y[i];
  }
  vector<pair<int, int>> ord;
  enum { DEL, INS, QRY };
  for (int i = 0; i < N; i++) {
    ord.emplace_back(DEL, i);
    ord.emplace_back(INS, i);
  }
  for (int i = 0; i < Q; i++) {
    ord.emplace_back(QRY, i);
  }
  auto get_y = [&](pair<int, int> a) {
    if (a.first == DEL) return D[a.second];
    if (a.first == INS) return B[a.second];
    if (a.first == QRY) return Y[a.second];
    abort();
  };
  sort(ord.begin(), ord.end(), [&](pair<int, int> i, pair<int, int> j) {
    if (get_y(i) != get_y(j)) return get_y(i) < get_y(j);
    return i.first < j.first;
  });
  constexpr int S = 2000;
  vector<pair<int, int>> tmp;
  for (int i = 0; i < N; i++) {
    tmp.emplace_back(A[i], i + N);
    tmp.emplace_back(C[i], i);
  }
  sort(tmp.begin(), tmp.end());
  vector<ll> ans(Q);
  for (int l = 0; l < ord.size(); l += S) {
    int r = min<int>(ord.size(), l + S);
    int y = get_y(ord[l]);
    vector<bool> used(N);
    for (int i = 0; i < l; i++) {
      if (ord[i].first == INS) {
        used[ord[i].second] = true;
      }
      if (ord[i].first == DEL) {
        used[ord[i].second] = false;
      }
    }
    vector<pair<int, int>> events;
    for (auto t : tmp) {
      if (used[t.second % N]) {
        events.push_back(t);
      }
    }
    vector<int> cnt(N);
    ll hassyu = 0;
    int k = 0;
    vector<int> queries;
    for (int i = l; i < r; i++) {
      if (ord[i].first == QRY) {
        queries.push_back(i);
      }
    }
    sort(queries.begin(), queries.end(), [&](int i, int j) {
      return X[ord[i].second] < X[ord[j].second];
      });
    for (int i : queries) {
      int q = ord[i].second;
      ll x = X[q];
      while (k < events.size() and events[k].first <= x) {
        if (events[k].second < N) {
          int id = events[k].second;
          if (--cnt[E[id]] == 0) hassyu ^= H[E[id]];
        } else {
          int id = events[k].second - N;
          if (cnt[E[id]]++ == 0) hassyu ^= H[E[id]];
        }
        k++;
      }
      for (int j = l; j < i; j++) {
        if (ord[j].first == INS) {
          int id = ord[j].second;
          if (A[id] <= x and x < C[id]) {
            if (cnt[E[id]]++ == 0) hassyu ^= H[E[id]];
          }
        }
        if (ord[j].first == DEL) {
          int id = ord[j].second;
          if (A[id] <= x and x < C[id]) {
            if (--cnt[E[id]] == 0) hassyu ^= H[E[id]];
          }
        }
      }
      ans[q] = hassyu;
      for (int j = i - 1; j >= l; j--) {
        if (ord[j].first == INS) {
          int id = ord[j].second;
          if (A[id] <= x and x < C[id]) {
            if (--cnt[E[id]] == 0) hassyu ^= H[E[id]];
          }
        }
        if (ord[j].first == DEL) {
          int id = ord[j].second;
          if (A[id] <= x and x < C[id]) {
            if (cnt[E[id]]++ == 0) hassyu ^= H[E[id]];
          }
        }
      }
    }
  }
  for (int i = 0; i < Q; i++) {
    cout << ans[i] << '\n';
  }
}
0