結果

問題 No.2220 Range Insert & Point Mex
ユーザー tnakao0123
提出日時 2024-07-05 10:54:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 1,324 bytes
コンパイル時間 679 ms
コンパイル使用メモリ 68,676 KB
最終ジャッジ日時 2025-02-22 02:12:43
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:46:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:51:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |     scanf("%d%d%d", &l, &r, &a), l--;
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:60:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |   scanf("%d", &qn);
      |   ~~~~~^~~~~~~~~~~
main.cpp:64:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   64 |     scanf("%d", &x), x--;
      |     ~~~~~^~~~~~~~~~

ソースコード

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 */

int cs[MAX_N];

/* 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) {
      if (cs[e.a]++ == 0) vs.erase(e.a);
    }
    else if (e.tp == Add) {
      if (--cs[e.a] == 0) vs.insert(e.a);
    }
    else
      printf("%d\n", *vs.begin());
  }
  
  return 0;
}

0