結果

問題 No.2220 Range Insert & Point Mex
ユーザー cho435cho435
提出日時 2023-02-17 23:24:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 1,692 bytes
コンパイル時間 2,423 ms
コンパイル使用メモリ 214,816 KB
実行使用メモリ 13,600 KB
最終ジャッジ日時 2023-09-28 18:14:59
合計ジャッジ時間 8,668 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,000 KB
testcase_01 AC 4 ms
7,148 KB
testcase_02 AC 4 ms
7,212 KB
testcase_03 AC 4 ms
7,028 KB
testcase_04 AC 4 ms
7,028 KB
testcase_05 AC 4 ms
7,220 KB
testcase_06 AC 4 ms
7,212 KB
testcase_07 AC 3 ms
6,124 KB
testcase_08 AC 4 ms
7,176 KB
testcase_09 AC 4 ms
7,204 KB
testcase_10 AC 4 ms
7,104 KB
testcase_11 AC 4 ms
7,112 KB
testcase_12 AC 4 ms
7,052 KB
testcase_13 AC 181 ms
12,920 KB
testcase_14 AC 180 ms
12,912 KB
testcase_15 AC 181 ms
12,756 KB
testcase_16 AC 180 ms
12,880 KB
testcase_17 AC 181 ms
12,808 KB
testcase_18 AC 182 ms
13,100 KB
testcase_19 AC 181 ms
12,812 KB
testcase_20 AC 199 ms
12,688 KB
testcase_21 AC 199 ms
12,820 KB
testcase_22 AC 199 ms
12,376 KB
testcase_23 AC 157 ms
12,812 KB
testcase_24 AC 137 ms
12,332 KB
testcase_25 AC 110 ms
10,420 KB
testcase_26 AC 129 ms
12,448 KB
testcase_27 AC 92 ms
12,080 KB
testcase_28 AC 38 ms
8,000 KB
testcase_29 AC 49 ms
8,012 KB
testcase_30 AC 50 ms
7,960 KB
testcase_31 AC 130 ms
13,600 KB
testcase_32 AC 97 ms
11,664 KB
testcase_33 AC 105 ms
11,292 KB
testcase_34 AC 152 ms
12,952 KB
testcase_35 AC 163 ms
12,968 KB
testcase_36 AC 146 ms
12,956 KB
testcase_37 AC 155 ms
13,136 KB
testcase_38 AC 137 ms
13,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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=max(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=max(str,sr);
    }
    if(str<q) SGadd(str,q,nw);
  }
  SGadd(0,q,nw+1);
  rep(i,q) cout<<SGget(i)<<'\n';
}
0