結果

問題 No.2220 Range Insert & Point Mex
ユーザー shinchanshinchan
提出日時 2023-02-17 22:24:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 380 ms / 2,000 ms
コード長 2,140 bytes
コンパイル時間 2,532 ms
コンパイル使用メモリ 214,940 KB
実行使用メモリ 14,692 KB
最終ジャッジ日時 2023-09-28 18:06:24
合計ジャッジ時間 14,051 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,860 KB
testcase_01 AC 6 ms
8,820 KB
testcase_02 AC 5 ms
8,972 KB
testcase_03 AC 6 ms
8,740 KB
testcase_04 AC 5 ms
8,720 KB
testcase_05 AC 5 ms
8,740 KB
testcase_06 AC 6 ms
8,740 KB
testcase_07 AC 6 ms
8,744 KB
testcase_08 AC 6 ms
8,748 KB
testcase_09 AC 6 ms
8,796 KB
testcase_10 AC 6 ms
8,932 KB
testcase_11 AC 6 ms
8,812 KB
testcase_12 AC 6 ms
8,744 KB
testcase_13 AC 378 ms
13,812 KB
testcase_14 AC 379 ms
13,912 KB
testcase_15 AC 380 ms
14,692 KB
testcase_16 AC 377 ms
13,792 KB
testcase_17 AC 376 ms
14,460 KB
testcase_18 AC 376 ms
14,584 KB
testcase_19 AC 377 ms
14,688 KB
testcase_20 AC 365 ms
13,984 KB
testcase_21 AC 368 ms
14,056 KB
testcase_22 AC 363 ms
14,312 KB
testcase_23 AC 370 ms
14,160 KB
testcase_24 AC 216 ms
14,000 KB
testcase_25 AC 349 ms
11,864 KB
testcase_26 AC 348 ms
14,524 KB
testcase_27 AC 55 ms
13,836 KB
testcase_28 AC 297 ms
8,800 KB
testcase_29 AC 303 ms
8,740 KB
testcase_30 AC 302 ms
8,880 KB
testcase_31 AC 342 ms
14,596 KB
testcase_32 AC 340 ms
11,868 KB
testcase_33 AC 342 ms
11,696 KB
testcase_34 AC 363 ms
14,112 KB
testcase_35 AC 364 ms
14,516 KB
testcase_36 AC 366 ms
13,344 KB
testcase_37 AC 366 ms
14,128 KB
testcase_38 AC 355 ms
13,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

struct SegmentTree {
private:
    ll n;
    vector<ll> node;
    ll ID = INF; // min -> INF, max, sum -> 0
    inline ll func(ll a, ll b){return min(a, b);} /////////

public:
    SegmentTree(vector<ll> v) {
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, ID);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = func(node[2*i+1], node[2*i+2]);
    }

    void add(ll x, ll val) {
        x += (n - 1);
        node[x] += val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = func(node[2*x+1], node[2*x+2]);
        }
    }

    ll get(ll a, ll b, ll k=0, ll l=0, ll r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return ID;
        if(a <= l && r <= b) return node[k];

        ll vl = get(a, b, 2*k+1, l, (l+r)/2);
        ll vr = get(a, b, 2*k+2, (l+r)/2, r);
        return func(vl, vr);
    }
};


int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<tuple<ll, ll, ll>> event;
    ll l, r, x;

    SegmentTree seg(vector<ll> (200001, 0LL));
    rep(i, n) {
        cin >> l >> r >> x;
        event.push_back({l, x, 1});
        event.push_back({r + 1, x, -1});
    }
    sort(be(event));
    ll q;
    cin >> q;
    ll id = 0;
    rep(i, q) {
        cin >> x;
        while(id < n * 2) {
            auto [z, a, f] = event[id];
            if(a >= 200001) {
                id++;
                continue;
            }
            if(z > x) break;
            seg.add(a, f);
            id++;
        }
        ll le = -1, ri = 200001; 
        while(ri - le > 1) {
            ll mid = (le + ri) / 2;
            if(seg.get(0, mid) == 0) ri = mid;
            else le = mid;
        }
        cout << le << endl;
    }

    return 0;
}
0