結果

問題 No.2220 Range Insert & Point Mex
ユーザー otoshigootoshigo
提出日時 2023-02-18 14:34:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,698 bytes
コンパイル時間 2,480 ms
コンパイル使用メモリ 219,916 KB
実行使用メモリ 11,768 KB
最終ジャッジ日時 2023-09-27 07:03:45
合計ジャッジ時間 11,073 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 195 ms
10,736 KB
testcase_21 AC 195 ms
11,192 KB
testcase_22 AC 196 ms
10,792 KB
testcase_23 AC 95 ms
10,412 KB
testcase_24 AC 69 ms
6,632 KB
testcase_25 AC 68 ms
6,424 KB
testcase_26 AC 76 ms
10,672 KB
testcase_27 AC 56 ms
7,344 KB
testcase_28 AC 20 ms
4,792 KB
testcase_29 AC 24 ms
4,792 KB
testcase_30 AC 24 ms
4,788 KB
testcase_31 AC 64 ms
9,748 KB
testcase_32 AC 60 ms
6,404 KB
testcase_33 AC 63 ms
7,108 KB
testcase_34 AC 120 ms
11,248 KB
testcase_35 AC 118 ms
10,792 KB
testcase_36 AC 127 ms
10,472 KB
testcase_37 AC 125 ms
10,492 KB
testcase_38 AC 86 ms
10,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

template <class T>
struct RangeMex{
    const T inf = numeric_limits<T>::max();
    set<pair<T,T>> se;
    RangeMex(){
        se.insert(make_pair(-inf,-inf));
        se.insert(make_pair(inf,inf));
    }
    void add(T x){
        auto id1 = se.lower_bound(make_pair(x+1,x+1));
        auto id2 = se.lower_bound(make_pair(x,x));
        id2--;
        pair<T,T> p1 = *id1, p2 = *id2;
        if (p1.first > x+1 && p2.second < x-1){
            se.insert(make_pair(x,x));
        }
        else if (p1.first > x+1){
            se.insert(make_pair(p2.first,x));
            se.erase(p2);
        }
        else if (p2.second < x-1){
            se.insert(make_pair(x,p1.second));
            se.erase(p1);
        }
        else{
            se.insert(make_pair(p2.first,p1.second));
            se.erase(p1);
            se.erase(p2);
        }
    }
    void erase(T x){
        auto id = se.lower_bound(make_pair(x+1,x+1));
        id--;
        pair<T,T> p = *id;
        if (p.second < x) return;
        if (p.first <= x-1) se.insert(make_pair(p.first,x-1));
        if (x+1 <= p.second) se.insert(make_pair(x+1,p.second));
        se.erase(p);
    }
    T mex(int l, int r){ //[l,r)のmex
        --r;
        auto id = se.lower_bound(make_pair(l,l));
        pair<T,T> p = *id;
        if (p.first != l){
            id--;
            pair<T,T> p2 = *id;
            if (p2.second < l) return l;
            else if (p2.second < r) return p2.second+1;
            else return -1;
        }
        else if (p.second < r) return p.second+1;
        else return -1;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<tuple<int,int,int>>T;
    vector<int>A(n);
    rep(i,n){
        int l,r,a;
        cin>>l>>r>>A[i];
        T.push_back(make_tuple(l,-1,i));
        T.push_back(make_tuple(r,1,i));
    }
    int q;
    cin>>q;
    rep(i,q){
        int x;
        cin>>x;
        T.push_back(make_tuple(x,0,i));
    }
    sort(all(T));
    vector<int>ans(q);
    RangeMex<int>M;
    int mex=0;
    map<int,int>mp;
    for(auto[x,t,i]:T){
        if(t==0){
            ans[i]=M.mex(0,1<<30);
        }else if(t==-1){
            M.add(A[i]);
        }else{
            M.erase(A[i]);
        }
    }
    rep(i,q)cout<<ans[i]<<"\n";
}
0