結果

問題 No.2220 Range Insert & Point Mex
ユーザー KudeKude
提出日時 2023-02-17 21:57:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 2,266 bytes
コンパイル時間 2,659 ms
コンパイル使用メモリ 238,056 KB
実行使用メモリ 21,940 KB
最終ジャッジ日時 2023-09-28 18:02:03
合計ジャッジ時間 8,349 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 212 ms
21,716 KB
testcase_14 AC 217 ms
21,824 KB
testcase_15 AC 215 ms
21,940 KB
testcase_16 AC 213 ms
21,648 KB
testcase_17 AC 211 ms
21,692 KB
testcase_18 AC 212 ms
21,760 KB
testcase_19 AC 214 ms
21,828 KB
testcase_20 AC 104 ms
15,420 KB
testcase_21 AC 105 ms
15,440 KB
testcase_22 AC 103 ms
15,292 KB
testcase_23 AC 114 ms
13,440 KB
testcase_24 AC 90 ms
13,264 KB
testcase_25 AC 79 ms
11,344 KB
testcase_26 AC 77 ms
12,068 KB
testcase_27 AC 44 ms
7,980 KB
testcase_28 AC 26 ms
6,800 KB
testcase_29 AC 30 ms
6,572 KB
testcase_30 AC 29 ms
6,696 KB
testcase_31 AC 80 ms
12,200 KB
testcase_32 AC 71 ms
10,352 KB
testcase_33 AC 75 ms
11,148 KB
testcase_34 AC 118 ms
13,572 KB
testcase_35 AC 131 ms
14,244 KB
testcase_36 AC 106 ms
11,324 KB
testcase_37 AC 116 ms
12,068 KB
testcase_38 AC 115 ms
19,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

template <class S>
struct value_compression : vector<S> {
  bool built = false;
  using VS = vector<S>;
  using VS::VS;
  value_compression(vector<S> v) : vector<S>(move(v)) {}
  void build() {
    sort(this->begin(), this->end());
    this->erase(unique(this->begin(), this->end()), this->end());
    built = true;
  }
  template <class T>
  void convert(T first, T last) {
    assert(built);
    for (; first != last; ++first) *first = (*this)(*first);
  }
  int operator()(S x) {
    assert(built);
    return lower_bound(this->begin(), this->end(), x) - this->begin();
  }
  void clear() {
    this->clear();
    built = false;
  }
};

int op(int x, int y) { return min(x, y); }
int e() { return 1001001001; }

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  value_compression<int> vc;
  vector<tuple<int, int, int>> lra(n);
  for(auto& [l, r, a]: lra) {
    cin >> l >> r >> a, l--;
    vc.emplace_back(l);
    vc.emplace_back(r);
  }
  int q;
  cin >> q;
  VI x(q);
  for(auto& xi: x) {
    cin >> xi, xi--;
    vc.emplace_back(xi);
  }
  vc.build();
  vector<vector<P>> evs(vc.size());
  for(auto& [l, r, a]: lra) if (a < n) {
    l = vc(l);
    r = vc(r);
    evs[l].emplace_back(a, 1);
    evs[r].emplace_back(a, -1);
  }
  segtree<int, op, e> seg(VI(n, 0));
  VI res(vc.size());
  rep(i, vc.size()) {
    for(auto [x, add]: evs[i]) {
      seg.set(x, seg.get(x) + add);
    }
    res[i] = seg.max_right(0, [](int x) { return x > 0; });
  }
  for(int xi: x) cout << res[vc(xi)] << '\n';
}
0