結果
問題 | No.2220 Range Insert & Point Mex |
ユーザー | kwm_t |
提出日時 | 2023-02-17 22:32:35 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 444 ms / 2,000 ms |
コード長 | 4,612 bytes |
コンパイル時間 | 3,063 ms |
コンパイル使用メモリ | 235,476 KB |
実行使用メモリ | 26,100 KB |
最終ジャッジ日時 | 2024-07-21 12:47:54 |
合計ジャッジ時間 | 9,983 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 172 ms
18,960 KB |
testcase_14 | AC | 169 ms
18,832 KB |
testcase_15 | AC | 170 ms
18,828 KB |
testcase_16 | AC | 170 ms
18,964 KB |
testcase_17 | AC | 170 ms
18,960 KB |
testcase_18 | AC | 172 ms
18,708 KB |
testcase_19 | AC | 169 ms
18,832 KB |
testcase_20 | AC | 444 ms
24,844 KB |
testcase_21 | AC | 442 ms
24,720 KB |
testcase_22 | AC | 435 ms
26,100 KB |
testcase_23 | AC | 189 ms
19,432 KB |
testcase_24 | AC | 160 ms
17,760 KB |
testcase_25 | AC | 129 ms
14,148 KB |
testcase_26 | AC | 141 ms
13,900 KB |
testcase_27 | AC | 120 ms
12,420 KB |
testcase_28 | AC | 23 ms
6,940 KB |
testcase_29 | AC | 25 ms
6,944 KB |
testcase_30 | AC | 26 ms
6,944 KB |
testcase_31 | AC | 73 ms
12,304 KB |
testcase_32 | AC | 71 ms
9,332 KB |
testcase_33 | AC | 82 ms
9,332 KB |
testcase_34 | AC | 188 ms
17,116 KB |
testcase_35 | AC | 205 ms
16,416 KB |
testcase_36 | AC | 150 ms
14,388 KB |
testcase_37 | AC | 168 ms
13,960 KB |
testcase_38 | AC | 165 ms
19,572 KB |
ソースコード
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } map<int, int> Compless(const vector<int> &v) { vector<int>vv = v; sort(all(vv)); vv.erase(unique(all(vv)), vv.end()); map<int, int>mp; rep(i, vv.size()) mp[vv[i]] = i; return mp; } template<typename T> struct RangeSet { // ReadMe:閉区間なことに注意 // member set<pair<T, T>>st; T TINF; // constructor RangeSet(T lim) { TINF = lim + 1; st.emplace(-TINF, -TINF); st.emplace(TINF, TINF); } // cover check bool IsCovered(T l, T r) { auto ite = prev(st.lower_bound({ l + 1,l + 1 })); return ((ite->first <= l) && (r <= ite->second)); } bool IsCovered(T x) { return IsCovered(x, x); } // get by covered pair<T, T> ByCovered(T l, T r) { auto ite = prev(st.lower_bound({ l + 1,l + 1 })); if ((ite->first <= l) && (r <= ite->second)) return *ite; return { -TINF, -TINF }; } pair<T, T> ByCovered(T x) { return ByCovered(x, x); } // getFront pair<T, T>getFront() { auto itr = st.begin(); itr++; return *itr; } // getBack pair<T, T>getBack() { auto itr = st.end(); itr--; itr--; return *itr; } // insert T Insert(T l, T r) { //insertでmargeしないver //st.emplace(l, r); //return 0; T sumErase = T(0); auto ite = prev(st.lower_bound({ l + 1,l + 1 })); // no need merge if (IsCovered(l, r))return sumErase; // first merge pos if ((ite->first <= l) && (l <= (ite->second + 1))) { l = ite->first; sumErase += ite->second - ite->first + 1; ite = st.erase(ite); } else ite = next(ite); // merge while (r > ite->second) { sumErase += ite->second - ite->first + 1; ite = st.erase(ite); } if (((ite->first - 1) <= r) && (r <= ite->second)) { r = ite->second; sumErase += ite->second - ite->first + 1; st.erase(ite); } st.emplace(l, r); return (r - l + 1) - sumErase; } T Insert(T x) { return Insert(x, x); } // erase T Erase(T l, T r) { T ret = T(0); auto get = ByCovered(l, r); if ((-TINF) != get.first) { st.erase(get); if (get.first != l)st.emplace(get.first, l - 1); if (get.second != r)st.emplace(r + 1, get.second); ret += r - l + 1; return ret; } auto ite = prev(st.lower_bound({ l + 1,l + 1 })); // first erase if ((ite->first <= l) && (l <= ite->second)) { ret += ite->second - l + 1; if (ite->first != l)st.emplace(ite->first, l - 1); ite = st.erase(ite); } else ite = next(ite); // erase while (ite->second <= r) { ret += ite->second - ite->first + 1; ite = st.erase(ite); } // last if ((ite->first <= r) && (r <= ite->second)) { ret += r - ite->first + 1; if (ite->second != r) st.emplace(r + 1, ite->second); st.erase(ite); } return ret; } T Erase(T x) { return Erase(x, x); } // range count int size() { return st.size() - 2; } // mex T Mex(T x = 0) { if (!IsCovered(x)) return x; auto ite = prev(st.lower_bound({ x + 1, x + 1 })); return ite->second + 1; } // debug void Debug() { for (auto[l, r] : st)cout << l << " " << r << endl; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int>l(n), r(n), a(n); vector<pair<int, P>>e; vector<int>v; rep(i, n) { cin >> l[i] >> r[i] >> a[i]; e.push_back({ l[i], { 0,a[i] } }); e.push_back({ r[i] + 1, { 1,a[i] } }); v.push_back(l[i]); v.push_back(r[i]); } int q; cin >> q; rep(i, q) { int x; cin >> x; e.push_back({ x, { 2,i } }); } auto cp = Compless(v); sort(all(e)); vector<int>ans(q); RangeSet<int>rs(INF); map<int, int>mp; rep(i, e.size()) { int idx = e[i].first; int t = e[i].second.first; int v = e[i].second.second; if (0 == t) { if (0 == mp[v]) rs.Insert(v); mp[v]++; } else if (1 == t) { mp[v]--; if (0 == mp[v]) rs.Erase(v); } else { ans[v] = rs.Mex(); } } rep(i, q)cout << ans[i] << endl; return 0; }