/* -*- coding: utf-8 -*- * * 2220.cc: No.2220 Range Insert & Point Mex - yukicoder */ #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; enum { Rmv, Add, Prt }; /* typedef */ using si = set; 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; /* 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; }