結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー beetbeet
提出日時 2018-11-27 12:08:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 332 ms / 1,000 ms
コード長 2,296 bytes
コンパイル時間 3,163 ms
コンパイル使用メモリ 217,032 KB
実行使用メモリ 45,440 KB
最終ジャッジ日時 2023-09-05 11:47:19
合計ジャッジ時間 9,618 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 310 ms
44,920 KB
testcase_01 AC 310 ms
44,756 KB
testcase_02 AC 109 ms
21,720 KB
testcase_03 AC 108 ms
21,568 KB
testcase_04 AC 108 ms
21,656 KB
testcase_05 AC 90 ms
21,664 KB
testcase_06 AC 107 ms
21,692 KB
testcase_07 AC 106 ms
21,660 KB
testcase_08 AC 48 ms
21,792 KB
testcase_09 AC 89 ms
21,564 KB
testcase_10 AC 90 ms
21,616 KB
testcase_11 AC 108 ms
21,604 KB
testcase_12 AC 294 ms
45,352 KB
testcase_13 AC 329 ms
45,440 KB
testcase_14 AC 316 ms
45,172 KB
testcase_15 AC 314 ms
45,188 KB
testcase_16 AC 309 ms
44,532 KB
testcase_17 AC 290 ms
44,520 KB
testcase_18 AC 319 ms
44,588 KB
testcase_19 AC 324 ms
45,136 KB
testcase_20 AC 298 ms
44,940 KB
testcase_21 AC 332 ms
44,512 KB
testcase_22 AC 311 ms
44,728 KB
testcase_23 AC 106 ms
21,672 KB
testcase_24 AC 90 ms
21,576 KB
testcase_25 AC 90 ms
21,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


using P = pair<Int, Int>;
struct SegmentTree{
  Int n;
  vector<P> v;
  vector<vector<Int> > dat;
  SegmentTree(){};
  SegmentTree(Int n,vector<P> v):v(v){init(n);build();};
  
  void init(Int n_){
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,vector<Int>());
  }  
  void build(){
    for(auto p:v)
      dat[p.first+n].emplace_back(p.second);    
    for(Int i=0;i<n;i++)
      sort(dat[i+n].begin(),dat[i+n].end());
    
    for(Int i=n-1;i;i--){
      merge(dat[(i<<1)|0].begin(),dat[(i<<1)|0].end(),
            dat[(i<<1)|1].begin(),dat[(i<<1)|1].end(),
            back_inserter(dat[i]));
    }
  }
  // [a,b) * [c,d)
  inline Int query(Int a,Int b,Int c,Int d){
    Int res=0;
    auto calc=[a,b,c,d](vector<Int> &x){
                auto latte=lower_bound(x.begin(),x.end(),d);
                auto malta=lower_bound(x.begin(),x.end(),c);
                return Int(latte-malta);
              };
    for(Int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) res+=calc(dat[l++]);
      if(r&1) res+=calc(dat[--r]);
    }
    return res;
  }
  
};


//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> x(n),a(n),b(n);
  for(Int i=0;i<n;i++) cin>>x[i]>>a[i]>>b[i];
  Int ans=0,res=n+1;
  vector<P> vp0,vp1,vp2;
  for(Int i=0;i<n;i++){
    if(x[i]==0) vp0.emplace_back(a[i],b[i]);
    if(x[i]==1) vp1.emplace_back(a[i],b[i]);
    if(x[i]==2) vp2.emplace_back(a[i],b[i]);
    if(x[i]==3) ans++;
  }

  const Int MAX = 1e5+100;
  SegmentTree seg0(MAX,vp0);
  SegmentTree seg1(MAX,vp1);
  SegmentTree seg2(MAX,vp2);

  auto calc=
    [&](Int p,Int q)->Int{
      Int res=ans;
      res+=seg0.query(p,MAX,q,MAX);
      res+=seg1.v.size()-seg1.query(0,p,0,q);
      res+=seg2.v.size();
      return res;
    };
  auto calc2=
    [&](Int p,Int q)->Int{
      Int res=ans;
      res+=seg1.query(p,MAX,q,MAX);
      res+=seg2.v.size()-seg2.query(0,p,0,q);
      return res;
    };
  
  Int l=MAX;
  for(Int p=0;p<MAX;p++){
    while(0<l&&calc(p,l)<m) l--;
    if(calc(p,l)<m) continue;
    chmin(res,calc2(p,l));
  }
  cout<<res<<endl;
  return 0;
}
0