結果

問題 No.2220 Range Insert & Point Mex
コンテスト
ユーザー C
提出日時 2026-10-02 15:09:00
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,282 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,252 ms
コンパイル使用メモリ 408,180 KB
実行使用メモリ 15,944 KB
最終ジャッジ日時 2026-10-02 15:09:18
合計ジャッジ時間 17,465 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
using namespace std;
using namespace atcoder;
using namespace __gnu_pbds;
using ll=long long;
using ld=long double;
using vll=vector<ll>;
using vvll=vector<vll>;
using pll=pair<ll,ll>;

// using mint=modint;

// template<class K,class V>
// using ordered_map=tree<K,V,less<K>,rb_tree_tag,tree_order_statistics_node_update>;


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

    //aはN以上であれば見なくていい
    //操作順はaの昇順でもいい

    ll N,Q;
    cin>>N;
    vector<vector<pll>>q(N);
    rep(i,0,N){
        ll l,r,a;
        cin>>l>>r>>a;
        if(a<N)q[a].push_back({l,r});
    }

    //区間たちをマージ
    rep(a,0,N){
        ll m=q[a].size();
        if(m==0)continue;
        sort(q[a].begin(),q[a].end());
        ll curl=q[a][0].first,curr=q[a][0].second;
        vector<pll>na;
        rep(i,1,m){
            auto [l,r]=q[a][i];
            if(l<=curr&&r>curr)curr=r;
            else if(l>curr){
                na.push_back({curl,curr});
                curl=l;
                curr=r;
            }
        }
        na.push_back({curl,curr});
        q[a]=na;
    }

    cin>>Q;
    set<pll>p;
    rep(i,0,Q){
        ll x;
        cin>>x;
        p.insert({x,i});
    }

    vll ans(Q,0);

    //昇順で操作を行います
    //aを取れないようなxであればmex(x)はもう決められます
    rep(a,0,N){
        ll m=q[a].size();
        if(m==0){
            for(auto [x,i]:p){
                ans[i]=a;
            }
            p.clear();
            break;
        }

        ll j=0;
        auto [l,r]=q[a][j];

        auto it=p.begin();
        while(it!=p.end()){
            auto [x,i]=*it;
            if(x<l){
                ans[i]=a;
                it=p.erase(it);
            }else{
                it=p.upper_bound({r,LLONG_MAX});
                ++j;
                if(j<m)l=q[a][j].first,r=q[a][j].second;
                else l=LLONG_MAX;
            }
        }
    }

    for(auto [x,i]:p)ans[i]=N;

    rep(i,0,Q)cout<<ans[i]<<'\n';
    cout<<endl;

}
0