結果

問題 No.961 Vibrant Fillumination
ユーザー 👑 emthrmemthrm
提出日時 2020-02-25 23:58:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 478 ms / 5,000 ms
コード長 4,758 bytes
コンパイル時間 2,802 ms
コンパイル使用メモリ 215,264 KB
実行使用メモリ 10,064 KB
最終ジャッジ日時 2024-04-21 15:46:23
合計ジャッジ時間 27,027 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 344 ms
9,932 KB
testcase_03 AC 354 ms
9,936 KB
testcase_04 AC 342 ms
9,804 KB
testcase_05 AC 359 ms
10,060 KB
testcase_06 AC 348 ms
9,928 KB
testcase_07 AC 353 ms
9,804 KB
testcase_08 AC 341 ms
9,932 KB
testcase_09 AC 342 ms
9,800 KB
testcase_10 AC 434 ms
9,808 KB
testcase_11 AC 438 ms
9,932 KB
testcase_12 AC 446 ms
9,804 KB
testcase_13 AC 445 ms
9,932 KB
testcase_14 AC 449 ms
10,060 KB
testcase_15 AC 408 ms
9,808 KB
testcase_16 AC 446 ms
9,932 KB
testcase_17 AC 411 ms
9,804 KB
testcase_18 AC 478 ms
9,928 KB
testcase_19 AC 463 ms
9,932 KB
testcase_20 AC 432 ms
9,928 KB
testcase_21 AC 403 ms
9,932 KB
testcase_22 AC 406 ms
9,800 KB
testcase_23 AC 404 ms
9,800 KB
testcase_24 AC 434 ms
10,060 KB
testcase_25 AC 436 ms
10,060 KB
testcase_26 AC 205 ms
9,932 KB
testcase_27 AC 197 ms
9,932 KB
testcase_28 AC 206 ms
9,928 KB
testcase_29 AC 204 ms
9,804 KB
testcase_30 AC 149 ms
9,932 KB
testcase_31 AC 84 ms
9,804 KB
testcase_32 AC 291 ms
9,676 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 360 ms
9,932 KB
testcase_35 AC 345 ms
9,928 KB
testcase_36 AC 364 ms
10,064 KB
testcase_37 AC 366 ms
9,932 KB
testcase_38 AC 353 ms
9,936 KB
testcase_39 AC 357 ms
10,056 KB
testcase_40 AC 352 ms
9,932 KB
testcase_41 AC 354 ms
9,932 KB
testcase_42 AC 356 ms
10,056 KB
testcase_43 AC 361 ms
9,932 KB
testcase_44 AC 364 ms
9,932 KB
testcase_45 AC 356 ms
9,804 KB
testcase_46 AC 365 ms
10,060 KB
testcase_47 AC 355 ms
9,932 KB
testcase_48 AC 370 ms
9,932 KB
testcase_49 AC 373 ms
10,060 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