結果

問題 No.961 Vibrant Fillumination
ユーザー ei1333333ei1333333
提出日時 2019-12-24 02:24:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,422 ms / 5,000 ms
コード長 5,172 bytes
コンパイル時間 2,827 ms
コンパイル使用メモリ 222,856 KB
実行使用メモリ 27,580 KB
最終ジャッジ日時 2024-09-22 17:08:22
合計ジャッジ時間 58,266 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1,127 ms
27,352 KB
testcase_03 AC 1,155 ms
27,392 KB
testcase_04 AC 1,091 ms
27,436 KB
testcase_05 AC 1,088 ms
27,580 KB
testcase_06 AC 1,167 ms
27,396 KB
testcase_07 AC 1,095 ms
27,392 KB
testcase_08 AC 985 ms
27,424 KB
testcase_09 AC 989 ms
27,236 KB
testcase_10 AC 1,417 ms
27,344 KB
testcase_11 AC 1,213 ms
27,180 KB
testcase_12 AC 1,405 ms
27,356 KB
testcase_13 AC 1,339 ms
27,352 KB
testcase_14 AC 1,279 ms
27,328 KB
testcase_15 AC 1,091 ms
27,320 KB
testcase_16 AC 1,330 ms
27,176 KB
testcase_17 AC 1,093 ms
27,320 KB
testcase_18 AC 1,329 ms
27,312 KB
testcase_19 AC 1,329 ms
27,200 KB
testcase_20 AC 1,218 ms
27,356 KB
testcase_21 AC 1,131 ms
27,444 KB
testcase_22 AC 1,104 ms
27,356 KB
testcase_23 AC 1,113 ms
27,304 KB
testcase_24 AC 1,288 ms
27,332 KB
testcase_25 AC 1,422 ms
27,436 KB
testcase_26 AC 847 ms
27,332 KB
testcase_27 AC 783 ms
27,472 KB
testcase_28 AC 941 ms
27,348 KB
testcase_29 AC 926 ms
27,424 KB
testcase_30 AC 273 ms
26,048 KB
testcase_31 AC 147 ms
27,264 KB
testcase_32 AC 394 ms
24,500 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 1,151 ms
27,444 KB
testcase_35 AC 1,056 ms
27,356 KB
testcase_36 AC 1,143 ms
27,308 KB
testcase_37 AC 1,095 ms
27,344 KB
testcase_38 AC 1,127 ms
27,236 KB
testcase_39 AC 988 ms
27,368 KB
testcase_40 AC 1,334 ms
27,248 KB
testcase_41 AC 969 ms
27,276 KB
testcase_42 AC 1,292 ms
27,208 KB
testcase_43 AC 1,237 ms
27,372 KB
testcase_44 AC 1,049 ms
27,324 KB
testcase_45 AC 1,015 ms
27,244 KB
testcase_46 AC 1,028 ms
27,228 KB
testcase_47 AC 991 ms
27,352 KB
testcase_48 AC 1,252 ms
27,440 KB
testcase_49 AC 1,357 ms
27,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

const int SQRT = 666;

int main() {
  int N;
  cin >> N;
  vector< int64 > H(N);
  cin >> H;
  vector< int > B(N), D(N), E(N);
  vector< pair< int, int > > A(N), C(N);
  vector< vector< int > > vs(N);
  vector< pair< int, int > > xs;
  vector< int > sz(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i].first >> B[i] >> C[i].first >> D[i] >> E[i];
    --E[i];
    sz[E[i]]++;
    A[i].second = i + 1;
    C[i].second = -(i + 1);
    xs.emplace_back(A[i]);
    xs.emplace_back(C[i]);
  }
  int Q;
  cin >> Q;
  vector< pair< int, int > > X(Q);
  vector< int > Y(Q);
  for(int i = 0; i < Q; i++) {
    cin >> X[i].first >> Y[i];
    X[i].second = inf;
    xs.emplace_back(X[i]);
  }


  sort(begin(xs), end(xs));

  vector< vector< pair< int, int > > > hs((xs.size() + SQRT - 1) / SQRT);
  for(int i = 0; i < Q; i++) {
    int pos = lower_bound(begin(xs), end(xs), X[i]) - begin(xs);
    hs[pos / SQRT].emplace_back(Y[i], i);
  }

  vector< vector< int > > Cs(xs.size()), As(xs.size()), Ds(2 * N), Bs(2 * N);
  for(int i = 0; i < N; i++) {
    int pos = lower_bound(begin(xs), end(xs), A[i]) - begin(xs);
    As[pos].emplace_back(i);
    pos = lower_bound(begin(xs), end(xs), C[i]) - begin(xs);
    Cs[pos].emplace_back(i);
    Bs[B[i]].emplace_back(i);
    Ds[D[i]].emplace_back(i);
  }


  auto include = [&](int idx, pair< int, int > x, int y) {
    return A[idx] <= x && x < C[idx] && B[idx] <= y && y < D[idx];
  };


  vector< int64 > ans(Q);

  for(int i = 0; i < hs.size(); i++) {
    auto &h = hs[i];
    sort(begin(h), end(h));

    int x = i * SQRT;
    int y = 0;

    vector< int > color(N);

    int64 hashed = 0;
    vector< int > exist(N);
    for(int j = 0; j < N; j++) {
      if(include(j, xs[x], y)) {
        exist[j] = true;
        if(color[E[j]]++ == 0) hashed ^= H[E[j]];
      }
    }
    for(auto &p : h) {
      while(xs[x] < X[p.second]) {
        ++x;
        for(auto &q : Cs[x]) {
          if(exist[q]) {
            exist[q] = false;
            if(--color[E[q]] == 0) hashed ^= H[E[q]];
          }
        }

        for(auto &q : As[x]) {
          if(!exist[q] && include(q, xs[x], y)) {
            exist[q] = true;
            if(color[E[q]]++ == 0) hashed ^= H[E[q]];
          }
        }

      }

      while(xs[x] > X[p.second]) {

        for(auto &q : As[x]) {
          if(exist[q]) {
            exist[q] = false;
            if(--color[E[q]] == 0) hashed ^= H[E[q]];
          }
        }

        for(auto &q : Cs[x]) {
          if(!exist[q] && include(q, xs[x - 1], y)) {
            exist[q] = true;
            if(color[E[q]]++ == 0) hashed ^= H[E[q]];
          }
        }


        --x;
      }

      while(y < p.first) {
        ++y;
        for(auto &q : Ds[y]) {
          if(exist[q]) {
            exist[q] = false;
            if(--color[E[q]] == 0) hashed ^= H[E[q]];
          }
        }

        for(auto &q : Bs[y]) {
          if(!exist[q] && include(q, xs[x], y)) {
            exist[q] = true;
            if(color[E[q]]++ == 0) hashed ^= H[E[q]];
          }
        }
      }

      ans[p.second] = hashed;
    }
  }

  for(int i = 0; i < Q; i++) {
    cout << ans[i] << "\n";
  }
}

0