結果

問題 No.961 Vibrant Fillumination
ユーザー risujirohrisujiroh
提出日時 2019-12-24 02:01:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 835 ms / 5,000 ms
コード長 4,465 bytes
コンパイル時間 2,513 ms
コンパイル使用メモリ 198,572 KB
実行使用メモリ 61,904 KB
最終ジャッジ日時 2023-10-23 23:50:32
合計ジャッジ時間 17,698 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 166 ms
28,904 KB
testcase_03 AC 174 ms
28,904 KB
testcase_04 AC 169 ms
28,904 KB
testcase_05 AC 170 ms
28,904 KB
testcase_06 AC 170 ms
28,904 KB
testcase_07 AC 168 ms
28,904 KB
testcase_08 AC 169 ms
28,904 KB
testcase_09 AC 169 ms
28,904 KB
testcase_10 AC 151 ms
21,248 KB
testcase_11 AC 153 ms
21,248 KB
testcase_12 AC 154 ms
21,248 KB
testcase_13 AC 150 ms
21,248 KB
testcase_14 AC 149 ms
21,248 KB
testcase_15 AC 144 ms
21,248 KB
testcase_16 AC 146 ms
21,248 KB
testcase_17 AC 150 ms
21,248 KB
testcase_18 AC 146 ms
21,248 KB
testcase_19 AC 148 ms
21,248 KB
testcase_20 AC 148 ms
21,248 KB
testcase_21 AC 148 ms
21,248 KB
testcase_22 AC 149 ms
21,248 KB
testcase_23 AC 143 ms
21,248 KB
testcase_24 AC 146 ms
21,248 KB
testcase_25 AC 147 ms
21,248 KB
testcase_26 AC 100 ms
17,552 KB
testcase_27 AC 116 ms
21,512 KB
testcase_28 AC 104 ms
17,552 KB
testcase_29 AC 123 ms
21,512 KB
testcase_30 AC 111 ms
20,600 KB
testcase_31 AC 91 ms
19,244 KB
testcase_32 AC 128 ms
21,776 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 494 ms
21,512 KB
testcase_35 AC 835 ms
21,512 KB
testcase_36 AC 571 ms
61,904 KB
testcase_37 AC 504 ms
51,080 KB
testcase_38 AC 512 ms
44,480 KB
testcase_39 AC 429 ms
60,056 KB
testcase_40 AC 371 ms
53,720 KB
testcase_41 AC 325 ms
49,232 KB
testcase_42 AC 274 ms
42,896 KB
testcase_43 AC 263 ms
40,520 KB
testcase_44 AC 241 ms
38,144 KB
testcase_45 AC 228 ms
36,560 KB
testcase_46 AC 218 ms
34,976 KB
testcase_47 AC 211 ms
34,184 KB
testcase_48 AC 202 ms
32,864 KB
testcase_49 AC 196 ms
31,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}

template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << ' ' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

template <class T> struct XorFenwickTree {
  const int n;
  vector<T> t;
  XorFenwickTree(int _n) : n(_n), t(n + 1) {}
  void add(int i, T x) { for (++i; i <= n; i += i & -i) t[i] ^= x; }
  T sum(int i) const {
    T s = 0;
    for (; i; i -= i & -i) s ^= t[i];
    return s;
  }
};

template <class T> struct FenwickTree {
  const int n;
  vector<T> t;
  FenwickTree(int _n) : n(_n), t(n + 1) {}
  void add(int i, T x) { for (++i; i <= n; i += i & -i) t[i] += x; }
  T sum(int i) const {
    T s = 0;
    for (; i; i -= i & -i) s += t[i];
    return s;
  }
  T sum(int l, int r) const { return sum(r) - sum(l); }
};


constexpr int th = 256;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long> h(n);
  for (auto&& e : h) {
    cin >> e;
  }
  struct Event {
    bool add;
    int c, l, r;
  };
  vector< vector<Event> > es(2 * n);
  vector<int> cnt(n);
  for (int i = 0; i < n; ++i) {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    --e;
    es[a].emplace_back(Event{true, e, b, d});
    es[c].emplace_back(Event{false, e, b, d});
    ++cnt[e];
  }
  int q;
  cin >> q;
  struct Query {
    int id, i;
  };
  vector< vector<Query> > qs(2 * n);
  for (int i = 0; i < q; ++i) {
    int x, y;
    cin >> x >> y;
    qs[x].emplace_back(Query{i, y});
  }
  vector<long long> res(q);
  XorFenwickTree<long long> ft(2 * n);
  vector< map<int, int> > mp(n);
  for (int t = 0; t < 2 * n; ++t) {
    for (auto e : es[t]) {
      if (cnt[e.c] >= th) {
        continue;
      }
      if (e.add) {
        vector<int> v{0};
        int sum = 0;
        for (auto p : mp[e.c]) {
          if (sum == 0 ^ (sum + p.second) == 0) {
            v.push_back(p.first);
          }
          sum += p.second;
        }
        v.push_back(2 * n);
        for (int i = 0; i < (int)v.size(); i += 2) {
          if (v[i + 1] <= e.l or e.r <= v[i]) {
            continue;
          }
          ft.add(max(v[i], e.l), h[e.c]);
          ft.add(min(v[i + 1], e.r), h[e.c]);
        }
        ++mp[e.c][e.l];
        --mp[e.c][e.r];
      } else {
        --mp[e.c][e.l];
        ++mp[e.c][e.r];
        vector<int> v{0};
        int sum = 0;
        for (auto p : mp[e.c]) {
          if (sum == 0 ^ (sum + p.second) == 0) {
            v.push_back(p.first);
          }
          sum += p.second;
        }
        v.push_back(2 * n);
        for (int i = 0; i < (int)v.size(); i += 2) {
          if (v[i + 1] <= e.l or e.r <= v[i]) {
            continue;
          }
          ft.add(max(v[i], e.l), h[e.c]);
          ft.add(min(v[i + 1], e.r), h[e.c]);
        }
      }
    }
    for (auto e : qs[t]) {
      res[e.id] = ft.sum(e.i + 1);
    }
  }
  vector<int> idx;
  for (int i = 0; i < n; ++i) {
    if (cnt[i] >= th) {
      idx.push_back(i);
    }
  }
  vector< FenwickTree<int> > fts(idx.size(), 2 * n);
  for (int t = 0; t < 2 * n; ++t) {
    for (auto e : es[t]) {
      if (cnt[e.c] < th) {
        continue;
      }
      e.c = lower_bound(begin(idx), end(idx), e.c) - begin(idx);
      if (e.add) {
        fts[e.c].add(e.l, 1);
        fts[e.c].add(e.r, -1);
      } else {
        fts[e.c].add(e.l, -1);
        fts[e.c].add(e.r, +1);
      }
    }
    for (auto e : qs[t]) {
      for (int k = 0; k < (int)idx.size(); ++k) {
        if (fts[k].sum(e.i + 1)) {
          res[e.id] ^= h[idx[k]];
        }
      }
    }
  }
  for (auto e : res) {
    cout << e << '\n';
  }
}
0