結果

問題 No.2220 Range Insert & Point Mex
ユーザー umimelumimel
提出日時 2023-02-17 22:57:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 2,467 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 182,236 KB
実行使用メモリ 19,532 KB
最終ジャッジ日時 2023-09-28 18:13:16
合計ジャッジ時間 10,433 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 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,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 264 ms
18,420 KB
testcase_14 AC 260 ms
18,136 KB
testcase_15 AC 263 ms
19,020 KB
testcase_16 AC 262 ms
18,644 KB
testcase_17 AC 262 ms
18,804 KB
testcase_18 AC 259 ms
18,700 KB
testcase_19 AC 261 ms
19,020 KB
testcase_20 AC 258 ms
17,808 KB
testcase_21 AC 259 ms
17,696 KB
testcase_22 AC 259 ms
18,508 KB
testcase_23 AC 238 ms
18,996 KB
testcase_24 AC 162 ms
13,728 KB
testcase_25 AC 195 ms
11,532 KB
testcase_26 AC 237 ms
18,292 KB
testcase_27 AC 77 ms
12,792 KB
testcase_28 AC 150 ms
6,428 KB
testcase_29 AC 153 ms
6,276 KB
testcase_30 AC 152 ms
7,540 KB
testcase_31 AC 229 ms
18,720 KB
testcase_32 AC 202 ms
12,568 KB
testcase_33 AC 202 ms
11,720 KB
testcase_34 AC 262 ms
17,940 KB
testcase_35 AC 258 ms
19,172 KB
testcase_36 AC 263 ms
19,136 KB
testcase_37 AC 258 ms
17,880 KB
testcase_38 AC 231 ms
19,532 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;

struct SegmentTree{
    ll n;
    vector<ll> dat;

    SegmentTree(ll n_){
        n = 1;
        while(n < n_) n*=2;
        dat.resize(2*n, 0);
    }

    void update(ll k, ll a){
        k += n-1;
        dat[k] += a;
        while(k > 0){
            k = (k-1)/2;
            dat[k] = min(dat[2*k+1], dat[2*k+2]);
        }
    }

    // the minimun element of [a, b)
    ll query(ll a, ll b){return query_sub(a, b, 0, 0, n);}

    ll query_sub(ll a, ll b, ll k, ll l, ll r){
        if(r <= a || b <= l){
            return INF;
        }else if(a <= l && r <= b){
            return dat[k];
        }else{
            ll vl = query_sub(a, b, 2*k+1, l, (l+r)/2);
            ll vr = query_sub(a, b, 2*k+2, (l+r)/2, r);
            return min(vl, vr);
        }
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;

    vector<tuple<ll, ll, ll>> ope(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});
    }
    sort(all(ope));

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

    vector<ll> ans(q);
    SegmentTree ST(n);
    for(ll i=0; i<n; i++) ST.update(i, i);
    while(!PQ.empty()){
        ll t = get<1>(PQ.top());
        if(t==0){
            ll l = get<0>(PQ.top());
            ll a = get<2>(PQ.top());
            if(a < n){
                ST.update(a, n);
            }
        }else if(t==1){
            ll x = get<0>(PQ.top());
            ll idx = get<2>(PQ.top());
            ll v = ST.query(0, n);
            if(v >= n){
                ans[idx]=n;
            }else{
                ans[idx]=v;
            }
        }else if(t==2){
            ll r = get<0>(PQ.top());
            ll a = get<2>(PQ.top());
            if(a < n){
                ST.update(a, -n);
            }
        }

        PQ.pop();
    }

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