結果
| 問題 | No.2220 Range Insert & Point Mex |
| コンテスト | |
| ユーザー |
C
|
| 提出日時 | 2026-10-02 15:12:10 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 56 ms / 2,000 ms |
| + 901µs | |
| コード長 | 2,266 bytes |
| 記録 | |
| コンパイル時間 | 6,738 ms |
| コンパイル使用メモリ | 409,716 KB |
| 実行使用メモリ | 15,964 KB |
| 最終ジャッジ日時 | 2026-10-02 15:12:23 |
| 合計ジャッジ時間 | 12,448 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#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';
}
C