結果

問題 No.2220 Range Insert & Point Mex
ユーザー umimelumimel
提出日時 2023-02-18 06:50:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 1,567 bytes
コンパイル時間 1,773 ms
コンパイル使用メモリ 180,520 KB
実行使用メモリ 13,932 KB
最終ジャッジ日時 2023-09-28 18:19:16
合計ジャッジ時間 7,385 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 143 ms
12,196 KB
testcase_14 AC 141 ms
12,868 KB
testcase_15 AC 141 ms
12,900 KB
testcase_16 AC 142 ms
13,232 KB
testcase_17 AC 143 ms
12,356 KB
testcase_18 AC 144 ms
13,932 KB
testcase_19 AC 142 ms
12,456 KB
testcase_20 AC 140 ms
12,632 KB
testcase_21 AC 140 ms
13,540 KB
testcase_22 AC 138 ms
12,772 KB
testcase_23 AC 148 ms
13,400 KB
testcase_24 AC 132 ms
11,168 KB
testcase_25 AC 84 ms
8,368 KB
testcase_26 AC 144 ms
12,488 KB
testcase_27 AC 109 ms
10,384 KB
testcase_28 AC 29 ms
4,768 KB
testcase_29 AC 32 ms
4,688 KB
testcase_30 AC 33 ms
4,692 KB
testcase_31 AC 120 ms
12,524 KB
testcase_32 AC 99 ms
9,716 KB
testcase_33 AC 100 ms
9,836 KB
testcase_34 AC 150 ms
12,396 KB
testcase_35 AC 150 ms
12,488 KB
testcase_36 AC 154 ms
12,636 KB
testcase_37 AC 153 ms
12,156 KB
testcase_38 AC 138 ms
12,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll MAX_N = 2e5;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> PQ;
    for(int i=0; i<n; i++){
        int l, r, a;
        cin >> l >> r >> a;
        l--; r--;
        PQ.push({l, 0, a});
        PQ.push({r, 2, a});
    }

    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int x; cin >> x;
        x--;
        PQ.push({x, 1, i});
    }

    vector<int> ans(q);
    vector<int> cnt(n, 0);
    set<int> st; rep(i, n) st.insert(i);
    while(!PQ.empty()){
        int t = get<1>(PQ.top());
        if(t==0){
            int a = get<2>(PQ.top());
            if(a<n){
                st.erase(a);
                cnt[a]++;
            }
        }else if(t==1){
            int idx = get<2>(PQ.top());
            if((int)st.size()==0) ans[idx]=n;
            else ans[idx]=*st.begin();
        }else if(t==2){
            int a = get<2>(PQ.top());
            if(a<n){
                cnt[a]--;
                if(cnt[a]==0) st.insert(a);
            }
        }

        PQ.pop();
    }

    for(int i=0; i<q; i++) cout << ans[i] << "\n";
}
0