結果

問題 No.961 Vibrant Fillumination
ユーザー risujirohrisujiroh
提出日時 2019-12-24 00:42:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,657 bytes
コンパイル時間 4,784 ms
コンパイル使用メモリ 188,784 KB
実行使用メモリ 21,212 KB
最終ジャッジ日時 2023-10-19 09:13:02
合計ジャッジ時間 11,551 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 90 ms
20,104 KB
testcase_31 AC 70 ms
18,944 KB
testcase_32 AC 114 ms
21,212 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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;
  }
};

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);
  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});
  }
  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);
  FenwickTree<long long> ft(2 * n);
  vector< set<int> > lr(n), ls(n), rs(n);
  for (int t = 0; t < 2 * n; ++t) {
    for (auto e : es[t]) {
      if (e.add) {
        {
          auto it = lr[e.c].lower_bound(e.l);
          if (it != begin(lr[e.c]) and ls[e.c].count(*--it)) {
            e.l = *it;
          }
        }
        {
          auto it = lr[e.c].upper_bound(e.r);
          if (it != end(lr[e.c]) and rs[e.c].count(*it)) {
            e.r = *it;
          }
        }
        lr[e.c].erase(lr[e.c].lower_bound(e.l), lr[e.c].lower_bound(e.r + 1));
        ls[e.c].erase(ls[e.c].lower_bound(e.l), ls[e.c].lower_bound(e.r + 1));
        rs[e.c].erase(rs[e.c].lower_bound(e.l), rs[e.c].lower_bound(e.r + 1));
      } else {
        {
          auto it = lr[e.c].lower_bound(e.l);
          if (it != end(lr[e.c]) and *it == e.l) {
            assert(ls[e.c].count(e.l));
            lr[e.c].erase(e.l);
            ls[e.c].erase(e.l);
          } else if (it != begin(lr[e.c]) and ls[e.c].count(*--it)) {
            lr[e.c].insert(e.l);
            rs[e.c].insert(e.l);
          }
        }
        {
          auto it = lr[e.c].upper_bound(e.r);
          if (it != begin(lr[e.c]) and *--it == e.r) {
            assert(rs[e.c].count(e.r));
            lr[e.c].erase(e.r);
            rs[e.c].erase(e.r);
          } else if (it != end(lr[e.c]) and rs[e.c].count(*it)) {
            lr[e.c].insert(e.r);
            ls[e.c].insert(e.r);
          }
        }
      }
      ft.add(e.l, h[e.c]);
      ft.add(e.r, h[e.c]);
    }
    for (auto e : qs[t]) {
      res[e.id] = ft.sum(e.i + 1);
    }
  }
  for (auto e : res) {
    cout << e << '\n';
  }
}
0