結果

問題 No.2220 Range Insert & Point Mex
ユーザー prism17prism17
提出日時 2023-02-18 23:36:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 416 ms / 2,000 ms
コード長 2,512 bytes
コンパイル時間 1,941 ms
コンパイル使用メモリ 183,040 KB
実行使用メモリ 68,176 KB
最終ジャッジ日時 2023-09-28 18:21:07
合計ジャッジ時間 9,555 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
50,460 KB
testcase_01 AC 20 ms
50,472 KB
testcase_02 AC 21 ms
50,472 KB
testcase_03 AC 21 ms
50,520 KB
testcase_04 AC 20 ms
50,460 KB
testcase_05 AC 21 ms
50,524 KB
testcase_06 AC 21 ms
50,464 KB
testcase_07 AC 21 ms
50,496 KB
testcase_08 AC 21 ms
50,468 KB
testcase_09 AC 21 ms
50,756 KB
testcase_10 AC 21 ms
50,568 KB
testcase_11 AC 20 ms
50,464 KB
testcase_12 AC 21 ms
50,460 KB
testcase_13 AC 212 ms
62,576 KB
testcase_14 AC 214 ms
62,636 KB
testcase_15 AC 212 ms
62,512 KB
testcase_16 AC 212 ms
62,512 KB
testcase_17 AC 211 ms
62,564 KB
testcase_18 AC 212 ms
62,580 KB
testcase_19 AC 211 ms
62,588 KB
testcase_20 AC 416 ms
68,132 KB
testcase_21 AC 414 ms
68,040 KB
testcase_22 AC 415 ms
68,176 KB
testcase_23 AC 210 ms
64,700 KB
testcase_24 AC 185 ms
64,316 KB
testcase_25 AC 137 ms
60,328 KB
testcase_26 AC 174 ms
62,092 KB
testcase_27 AC 131 ms
59,316 KB
testcase_28 AC 44 ms
53,044 KB
testcase_29 AC 47 ms
53,152 KB
testcase_30 AC 47 ms
53,152 KB
testcase_31 AC 87 ms
57,580 KB
testcase_32 AC 85 ms
57,376 KB
testcase_33 AC 90 ms
57,360 KB
testcase_34 AC 228 ms
62,340 KB
testcase_35 AC 248 ms
62,472 KB
testcase_36 AC 181 ms
60,760 KB
testcase_37 AC 191 ms
60,788 KB
testcase_38 AC 170 ms
64,620 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void solve()’ 内:
main.cpp:74:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   74 |   for (auto &[l, r, x] : a) {
      |              ^

ソースコード

diff #

// Problem: No.2220 Range Insert & Point Mex
// Contest: yukicoder
// URL: https://yukicoder.me/problems/no/2220
// Memory Limit: 512 MB
// Time Limit: 2000 ms

#include <bits/stdc++.h>

#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define dbg(x) cout << #x << " = " << (x) << "\n";
#define popcount(x) __builtin_popcountll((x))
#define all(v) (v).begin(), (v).end()
#define pb emplace_back
#define x first
#define y second

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

struct BIT {
  int sz;
  vector<int> bit;
  int lowbit(int x) { return x & -x; }
  void add(int x, ll v) {
    for (int i = ++x; i <= sz; i += lowbit(i)) {
      bit[i] += v;
    }
  }
  ll ask(int x) {
    if (x < 0) return 0;
    ll ret = 0;
    for (int i = ++x; i >= 1; i -= lowbit(i)) {
      ret += bit[i];
    }
    return ret;
  }
  void build(int _n) {
    sz = _n;
    bit = vector<int>(sz + 10, 0);
  }
} bit;

const int N = 1e6 + 7;
int n, q;
int ans[N];
vector<int> in[N], out[N];
vector<int> v, vv;
int get(int x) { return lower_bound(all(v), x) - v.begin() + 1; }
int g(int x) { return lower_bound(all(vv), x) - vv.begin(); }
void solve() {
  cin >> n;
  vector<array<int, 3>> a(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
    v.pb(a[i][0]);
    v.pb(a[i][1]);
  }
  cin >> q;
  vector<int> Q(q);
  for (int &i : Q) {
    cin >> i;
    v.pb(i);
  }
  v.pb(INT_MAX);
  sort(all(v));
  v.erase(unique(all(v)), v.end());
  map<int, int> cnt;
  for (auto &[l, r, x] : a) {
    int nl = get(l), nr = get(r + 1);
    in[nl].pb(x);
    out[nr].pb(x);
    vv.pb(x);
    if (x) vv.pb(x - 1);
    vv.pb(x + 1);
  }
  vv.pb(0);
  sort(all(vv));
  vv.erase(unique(all(vv)), vv.end());
  bit.build(vv.size() + 1);

  for (int i = 1; i <= v.size(); i++) {
    for (auto &it : in[i]) {
      if (++cnt[it] == 1) {
        bit.add(g(it), 1);
      }
    }
    for (auto &it : out[i]) {
      if (--cnt[it] == 0) {
        bit.add(g(it), -1);
      }
    }
    int l = 0, r = vv.size() + 1;
    while (l < r) {
      int mid = l + r + 1 >> 1;
      if (bit.ask(mid) == mid + 1)
        l = mid;
      else
        r = mid - 1;
    }
    if (bit.ask(l) == l + 1) ++l;
    ans[i] = l;
  }
  for (int &i : Q) {
    cout << ans[get(i)] << "\n";
  }
}

int main() {
  fastio;
  //    freopen("input.txt", "r", stdin);
  int t = 1;
  //    cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
0