結果

問題 No.961 Vibrant Fillumination
ユーザー 👑 emthrmemthrm
提出日時 2020-02-25 23:58:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 427 ms / 5,000 ms
コード長 4,758 bytes
コンパイル時間 4,274 ms
コンパイル使用メモリ 219,164 KB
実行使用メモリ 9,840 KB
最終ジャッジ日時 2023-08-03 17:35:38
合計ジャッジ時間 33,774 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,924 KB
testcase_02 AC 324 ms
9,580 KB
testcase_03 AC 337 ms
9,572 KB
testcase_04 AC 331 ms
9,640 KB
testcase_05 AC 341 ms
9,740 KB
testcase_06 AC 326 ms
9,840 KB
testcase_07 AC 331 ms
9,740 KB
testcase_08 AC 331 ms
9,576 KB
testcase_09 AC 332 ms
9,680 KB
testcase_10 AC 419 ms
9,648 KB
testcase_11 AC 416 ms
9,624 KB
testcase_12 AC 424 ms
9,680 KB
testcase_13 AC 418 ms
9,624 KB
testcase_14 AC 427 ms
9,576 KB
testcase_15 AC 395 ms
9,588 KB
testcase_16 AC 422 ms
9,592 KB
testcase_17 AC 390 ms
9,620 KB
testcase_18 AC 420 ms
9,576 KB
testcase_19 AC 420 ms
9,648 KB
testcase_20 AC 418 ms
9,576 KB
testcase_21 AC 387 ms
9,636 KB
testcase_22 AC 391 ms
9,660 KB
testcase_23 AC 388 ms
9,676 KB
testcase_24 AC 410 ms
9,644 KB
testcase_25 AC 420 ms
9,656 KB
testcase_26 AC 189 ms
9,644 KB
testcase_27 AC 181 ms
9,656 KB
testcase_28 AC 193 ms
9,576 KB
testcase_29 AC 192 ms
9,592 KB
testcase_30 AC 139 ms
9,656 KB
testcase_31 AC 78 ms
9,588 KB
testcase_32 AC 274 ms
9,660 KB
testcase_33 AC 2 ms
4,924 KB
testcase_34 AC 350 ms
9,584 KB
testcase_35 AC 337 ms
9,660 KB
testcase_36 AC 349 ms
9,656 KB
testcase_37 AC 353 ms
9,572 KB
testcase_38 AC 341 ms
9,620 KB
testcase_39 AC 345 ms
9,588 KB
testcase_40 AC 337 ms
9,592 KB
testcase_41 AC 345 ms
9,572 KB
testcase_42 AC 346 ms
9,740 KB
testcase_43 AC 350 ms
9,648 KB
testcase_44 AC 353 ms
9,592 KB
testcase_45 AC 342 ms
9,672 KB
testcase_46 AC 349 ms
9,568 KB
testcase_47 AC 345 ms
9,572 KB
testcase_48 AC 359 ms
9,836 KB
testcase_49 AC 356 ms
9,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<ll> h(n); REP(i, n) cin >> h[i];
  vector<int> a(n), b(n), c(n), d(n), e(n);
  vector<pair<int, int> > xs, ys;
  REP(i, n) {
    cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i]; --e[i];
    xs.emplace_back(a[i], i);
    xs.emplace_back(c[i], n + i);
    ys.emplace_back(b[i], i);
    ys.emplace_back(d[i], n + i);
  }
  int Q; cin >> Q;
  vector<int> p(Q), q(Q);
  REP(i, Q) {
    cin >> p[i] >> q[i];
    xs.emplace_back(p[i], n * 2 + i);
    ys.emplace_back(q[i], n * 2 + i);
  }
  sort(ALL(xs));
  int X = 0;
  for (pair<int, int> pr : xs) {
    if (pr.second >= n * 2) {
      p[pr.second - n * 2] = X - 1;
    } else {
      if (pr.second < n) {
        a[pr.second] = X;
      } else {
        c[pr.second - n] = X;
      }
      ++X;
    }
  }
  ++X;
  vector<int> in_x(X, -1), out_x(X, -1);
  REP(i, n) {
    in_x[a[i]] = i;
    out_x[c[i]] = i;
    // cout << 'x' << i << " [" << a[i] << ',' << c[i] << "]\n";
  }
  // REP(i, X) cout << in_x[i] << " \n"[i + 1 == X];
  // REP(i, X) cout << out_x[i] << " \n"[i + 1 == X];
  sort(ALL(ys));
  int Y = 0;
  for (pair<int, int> pr : ys) {
    if (pr.second >= n * 2) {
      q[pr.second - n * 2] = Y - 1;
    } else {
      if (pr.second < n) {
        b[pr.second] = Y;
      } else {
        d[pr.second - n] = Y;
      }
      ++Y;
    }
  }
  ++Y;
  vector<int> in_y(Y, -1), out_y(Y, -1);
  REP(i, n) {
    in_y[b[i]] = i;
    out_y[d[i]] = i;
    // cout << 'y' << i << " [" << b[i] << ',' << d[i] << "]\n";
  }
  int B = sqrt(X), m = (X + B - 1) / B;
  vector<vector<int> > query(m);
  REP(i, Q) {
    if (p[i] != -1 && q[i] != -1) query[p[i] / B].emplace_back(i);
    // cout << p[i] << ' ' << q[i] << '\n';
  }
  vector<ll> ans(Q, 0);
  REP(block, m) {
    sort(ALL(query[block]), [&](int l, int r) { return q[l] < q[r]; });
    ll hash = 0;
    vector<int> cnt(n, 0);
    int x = block * B, y = 0;
    for (int idx : query[block]) {
      for (; y <= q[idx]; ++y) {
        if (in_y[y] != -1) {
          int film = in_y[y];
          if (a[film] < x && x <= c[film]) {
            if (cnt[e[film]] == 0) hash ^= h[e[film]];
            ++cnt[e[film]];
          }
        }
        if (out_y[y] != -1) {
          int film = out_y[y];
          if (a[film] < x && x <= c[film]) {
            --cnt[e[film]];
            if (cnt[e[film]] == 0) hash ^= h[e[film]];
          }
        }
        // cout << '(' << x << ',' << y << ")  ";
        // REP(i, n) cout << cnt[i] << " \n"[i + 1 == n];
      }
      for (; x <= p[idx]; ++x) {
        if (in_x[x] != -1) {
          int film = in_x[x];
          if (b[film] < y && y <= d[film]) {
            if (cnt[e[film]] == 0) hash ^= h[e[film]];
            ++cnt[e[film]];
          }
        }
        if (out_x[x] != -1) {
          int film = out_x[x];
          if (b[film] < y && y <= d[film]) {
            --cnt[e[film]];
            if (cnt[e[film]] == 0) hash ^= h[e[film]];
          }
        }
        // cout << '(' << x << ',' << y << ")  ";
        // REP(i, n) cout << cnt[i] << " \n"[i + 1 == n];
      }
      while (x > p[idx] + 1) {
        --x;
        if (in_x[x] != -1) {
          int film = in_x[x];
          if (b[film] < y && y <= d[film]) {
            --cnt[e[film]];
            if (cnt[e[film]] == 0) hash ^= h[e[film]];
          }
        }
        if (out_x[x] != -1) {
          int film = out_x[x];
          if (b[film] < y && y <= d[film]) {
            if (cnt[e[film]] == 0) hash ^= h[e[film]];
            ++cnt[e[film]];
          }
        }
        // cout << '(' << x << ',' << y << ")  ";
        // REP(i, n) cout << cnt[i] << " \n"[i + 1 == n];
      }
      ans[idx] = hash;
    }
  }
  REP(i, Q) cout << ans[i] << '\n';
  return 0;
}
0