結果

問題 No.2220 Range Insert & Point Mex
ユーザー hourenhouren
提出日時 2023-02-17 22:38:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 2,194 bytes
コンパイル時間 3,558 ms
コンパイル使用メモリ 181,616 KB
実行使用メモリ 6,872 KB
最終ジャッジ日時 2023-09-28 18:11:01
合計ジャッジ時間 6,063 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 90 ms
5,944 KB
testcase_14 AC 91 ms
6,244 KB
testcase_15 AC 90 ms
5,936 KB
testcase_16 AC 90 ms
5,928 KB
testcase_17 AC 89 ms
5,996 KB
testcase_18 AC 90 ms
5,920 KB
testcase_19 AC 91 ms
6,028 KB
testcase_20 AC 57 ms
4,380 KB
testcase_21 AC 57 ms
4,376 KB
testcase_22 AC 57 ms
4,380 KB
testcase_23 AC 78 ms
6,728 KB
testcase_24 AC 63 ms
6,872 KB
testcase_25 AC 61 ms
5,148 KB
testcase_26 AC 77 ms
6,664 KB
testcase_27 AC 42 ms
6,784 KB
testcase_28 AC 15 ms
4,376 KB
testcase_29 AC 18 ms
4,380 KB
testcase_30 AC 18 ms
4,380 KB
testcase_31 AC 59 ms
6,728 KB
testcase_32 AC 45 ms
4,376 KB
testcase_33 AC 50 ms
4,384 KB
testcase_34 AC 63 ms
4,808 KB
testcase_35 AC 69 ms
4,824 KB
testcase_36 AC 62 ms
4,760 KB
testcase_37 AC 67 ms
4,752 KB
testcase_38 AC 70 ms
5,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);
template <typename T>
struct BIT{
    int n;
    vector<T> data;
    BIT(int n=0) : n(n), data(n+1){}
    T sum(int i){
        T res = 0;
        for(; i; i -= i&-i){
            res += data[i];
        }
        return res;
    }
    void add(int i, T x){
        for(; i <= n; i += i&-i){
            data[i] += x;
        }
    }
    int lower_bound(T w){
        int x = 0, r = 1;
        while(r < n) r <<= 1;
        for(int len = r; len > 0; len = len >> 1){
            if(x+len < n && data[x+len] < w){
                w -= data[x+len];
                x += len;
            }
        }
        return x+1;
    }
};
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n;
    priority_queue<asc(T)> pq1;
    priority_queue<asc(P)> pq2;
    rep(i,n){
        int l,r,a;
        cin >> l >> r >> a;
        r++;
        a++;
        if(a<=n) pq1.push({l,r,a});
    }
    vector<int> cnt(n+1,0);
    BIT<int> bit(n+1);
    cin >> q;
    rep(i,q){
        int x;
        cin >> x;
        while(pq1.size() && get<0>(pq1.top())<=x){
            int l,r,a;
            tie(l,r,a) = pq1.top();
            pq1.pop();
            pq2.push({r,a});
            if(!cnt[a]) bit.add(a,1);
            cnt[a]++;
        }
        while(pq2.size() && pq2.top().first<=x){
            int r,a;
            tie(r,a) = pq2.top();
            pq2.pop();
            if(cnt[a]==1) bit.add(a,-1);
            cnt[a]--;
        }
        int ok = 0, ng = n+1;
        while(ng-ok>1){
            int md = (ok + ng) / 2;
            if(bit.sum(md)==md) ok = md;
            else ng = md;
        }
        cout << ok << '\n';
    }
    return 0;
}
0