結果
| 問題 | No.2220 Range Insert & Point Mex | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-02-17 23:20:14 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,674 bytes | 
| コンパイル時間 | 2,374 ms | 
| コンパイル使用メモリ | 209,932 KB | 
| 最終ジャッジ日時 | 2025-02-10 18:10:47 | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 WA * 15 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<int(n);i++)
int dat_sz=1<<18;
vector<ll> dat(dat_sz*2,1e18);
void SGadd(int a,int b,ll ad,int k=1,int x=0,int y=dat_sz){
  if(y<=a||b<=x) return;
  if(a<=x&&y<=b) {
    dat.at(k)=min(dat.at(k),ad);
    return;
  }
  int md=(x+y)/2;
  SGadd(a,b,ad,k*2,x,md);
  SGadd(a,b,ad,k*2+1,md,y);
}
ll SGget(int k){
  k+=dat_sz;
  ll ans=1e18;
  while(k>0){
    ans=min(ans,dat.at(k));
    k/=2;
  }
  return ans;
}
int main(){
  ll n;
  cin>>n;
  vector<ll> l(n),r(n),a(n);
  rep(i,n) cin>>l.at(i)>>r.at(i)>>a.at(i);
  ll q;
  cin>>q;
  vector<ll> x(q);
  rep(i,q) cin>>x.at(i);
  assert(is_sorted(x.begin(),x.end()));
  vector<ll> nl(n),nr(n);
  rep(i,n){
    nl.at(i)=lower_bound(x.begin(),x.end(),l.at(i))-x.begin();
    nr.at(i)=upper_bound(x.begin(),x.end(),r.at(i))-x.begin();
  }
  vector<ll> pr(n);
  rep(i,n) pr.at(i)=i;
  sort(pr.begin(),pr.end(),[&](int i,int j){
    return a.at(i)<a.at(j);
  });
  vector<pair<int,int>> st;
  ll nw=0;
  if(a.at(pr.at(0))!=0) SGadd(0,q,0);
  for(int i:pr){
    if(nw<a.at(i)){
      sort(st.begin(),st.end());
      int str=0;
      for(auto [sl,sr]:st){
        if(str<sl) SGadd(str,sl,nw);
        str=sr;
      }
      if(str<q) SGadd(str,q,nw);
      st.clear();
      if(nw+1!=a.at(i)){
        SGadd(0,q,nw+1);
        break;
      }
      nw++;
    }
    st.emplace_back(nl.at(i),nr.at(i));
  }
  if(!st.empty()){
    sort(st.begin(),st.end());
    int str=0;
    for(auto [sl,sr]:st){
      if(str<sl) SGadd(str,sl,nw);
      str=sr;
    }
    if(str<q) SGadd(str,q,nw);
  }
  SGadd(0,q,nw+1);
  rep(i,q) cout<<SGget(i)<<'\n';
}
            
            
            
        