結果

問題 No.961 Vibrant Fillumination
ユーザー ei1333333ei1333333
提出日時 2019-12-24 02:14:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,641 bytes
コンパイル時間 3,173 ms
コンパイル使用メモリ 219,008 KB
実行使用メモリ 23,580 KB
最終ジャッジ日時 2023-10-19 10:28:40
合計ジャッジ時間 105,951 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3,306 ms
23,532 KB
testcase_03 AC 2,328 ms
23,568 KB
testcase_04 AC 2,361 ms
23,468 KB
testcase_05 AC 2,322 ms
23,524 KB
testcase_06 AC 3,442 ms
23,468 KB
testcase_07 AC 3,387 ms
23,520 KB
testcase_08 AC 3,354 ms
23,512 KB
testcase_09 AC 2,795 ms
23,532 KB
testcase_10 AC 4,016 ms
23,572 KB
testcase_11 AC 3,445 ms
23,568 KB
testcase_12 AC 3,552 ms
23,568 KB
testcase_13 AC 3,889 ms
23,576 KB
testcase_14 AC 3,596 ms
23,568 KB
testcase_15 AC 3,380 ms
23,572 KB
testcase_16 AC 3,687 ms
23,568 KB
testcase_17 AC 3,575 ms
23,468 KB
testcase_18 AC 3,610 ms
23,468 KB
testcase_19 AC 3,361 ms
23,468 KB
testcase_20 AC 3,751 ms
23,468 KB
testcase_21 AC 3,652 ms
23,468 KB
testcase_22 AC 3,592 ms
23,468 KB
testcase_23 AC 3,618 ms
23,468 KB
testcase_24 AC 3,203 ms
23,564 KB
testcase_25 AC 3,560 ms
23,468 KB
testcase_26 AC 2,813 ms
23,580 KB
testcase_27 AC 2,125 ms
23,552 KB
testcase_28 AC 2,481 ms
23,576 KB
testcase_29 AC 2,354 ms
23,468 KB
testcase_30 TLE -
testcase_31 TLE -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = 150;

int main() {
  int N;
  cin >> N;
  vector< int64 > H(N);
  cin >> H;
  vector< int > A(N), B(N), C(N), D(N), E(N);
  vector< vector< int > > vs(N);
  vector< int > sz(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i];
    --E[i];
    sz[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< vector< pair< int, int > > > hs((2 * N + SQRT - 1) / SQRT);
  for(int i = 0; i < Q; i++) {
    hs[X[i] / SQRT].emplace_back(Y[i], i);
  }

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


  auto include = [&](int idx, 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 = SQRT * i;
    int y = 0;

    vector< int > color(N);

    int64 hashed = 0;
    vector< int > exist(N);
    for(int j = 0; j < N; j++) {
      if(include(j, x, y)) {
        exist[j] = true;
        if(color[E[j]]++ == 0) hashed ^= H[E[j]];
      }
    }
    for(auto &p : h) {
      while(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, x, y)) {
            exist[q] = true;
            if(color[E[q]]++ == 0) hashed ^= H[E[q]];
          }
        }

      }

      while(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, 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, 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