結果

問題 No.2220 Range Insert & Point Mex
ユーザー hourenhouren
提出日時 2023-02-17 22:38:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 2,194 bytes
コンパイル時間 1,640 ms
コンパイル使用メモリ 185,168 KB
実行使用メモリ 7,020 KB
最終ジャッジ日時 2024-07-21 12:49:58
合計ジャッジ時間 5,319 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

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