結果

問題 No.2220 Range Insert & Point Mex
ユーザー umimelumimel
提出日時 2023-02-18 06:47:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 1,507 bytes
コンパイル時間 1,826 ms
コンパイル使用メモリ 180,664 KB
実行使用メモリ 17,844 KB
最終ジャッジ日時 2023-09-28 18:19:45
合計ジャッジ時間 10,428 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 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,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 275 ms
16,944 KB
testcase_14 AC 274 ms
17,196 KB
testcase_15 AC 274 ms
17,148 KB
testcase_16 AC 272 ms
17,784 KB
testcase_17 AC 274 ms
16,848 KB
testcase_18 AC 273 ms
16,904 KB
testcase_19 AC 273 ms
16,676 KB
testcase_20 AC 270 ms
17,812 KB
testcase_21 AC 272 ms
17,588 KB
testcase_22 AC 272 ms
17,096 KB
testcase_23 AC 281 ms
17,088 KB
testcase_24 AC 200 ms
14,760 KB
testcase_25 AC 207 ms
11,080 KB
testcase_26 AC 274 ms
16,700 KB
testcase_27 AC 118 ms
14,304 KB
testcase_28 AC 147 ms
6,124 KB
testcase_29 AC 152 ms
6,192 KB
testcase_30 AC 152 ms
7,180 KB
testcase_31 AC 240 ms
17,132 KB
testcase_32 AC 218 ms
12,848 KB
testcase_33 AC 222 ms
12,944 KB
testcase_34 AC 282 ms
16,888 KB
testcase_35 AC 276 ms
16,628 KB
testcase_36 AC 282 ms
16,828 KB
testcase_37 AC 283 ms
17,588 KB
testcase_38 AC 261 ms
17,844 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);
    
    ll n; cin >> n;
    priority_queue<tuple<ll, ll, ll>, vector<tuple<ll, ll, ll>>, greater<tuple<ll, ll, ll>>> PQ;
    rep(i, n){
        ll l, r, a;
        cin >> l >> r >> a;
        l--; r--;
        PQ.push({l, 0, a});
        PQ.push({r, 2, a});
    }

    ll q;
    cin >> q;
    rep(i, q){
        ll x; cin >> x;
        x--;
        PQ.push({x, 1, i});
    }

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

        PQ.pop();
    }

    rep(i, q) cout << ans[i] << endl;
}
0