結果

問題 No.2220 Range Insert & Point Mex
ユーザー tnakao0123tnakao0123
提出日時 2024-07-05 10:50:25
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,252 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 70,464 KB
実行使用メモリ 12,668 KB
最終ジャッジ日時 2024-07-05 10:50:32
合計ジャッジ時間 6,329 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2220.cc:  No.2220 Range Insert & Point Mex - yukicoder
 */

#include<cstdio>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 100000;

enum { Rmv, Add, Prt };

/* typedef */

using si = set<int>;

struct Event {
  int tp, x, a;
  Event() {}
  Event(int _tp, int _x): tp(_tp), x(_x), a(-1) {}
  Event(int _tp, int _x, int _a): tp(_tp), x(_x), a(_a) {}

  bool operator<(const Event &e) const {
    return x < e.x || (x == e.x && tp < e.tp);
  }
};

using vev = vector<Event>;

/* global variables */

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  vev es;
  for (int i = 0; i < n; i++) {
    int l, r, a;
    scanf("%d%d%d", &l, &r, &a), l--;

    if (a < n) {
      es.push_back(Event(Rmv, l, a));
      es.push_back(Event(Add, r, a));
    }
  }

  int qn;
  scanf("%d", &qn);

  while (qn--) {
    int x;
    scanf("%d", &x), x--;
    es.push_back(Event(Prt, x));
  }

  sort(es.begin(), es.end());

  si vs;
  for (int i = 0; i <= n; i++) vs.insert(i);

  for (auto &e: es) {
    if (e.tp == Rmv)
      vs.erase(e.a);
    else if (e.tp == Add)
      vs.insert(e.a);
    else
      printf("%d\n", *vs.begin());
  }
  
  return 0;
}

0