結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー beetbeet
提出日時 2018-11-27 12:02:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,364 bytes
コンパイル時間 2,804 ms
コンパイル使用メモリ 216,624 KB
実行使用メモリ 45,528 KB
最終ジャッジ日時 2023-09-05 11:38:29
合計ジャッジ時間 22,680 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 AC 381 ms
21,800 KB
testcase_03 AC 363 ms
21,788 KB
testcase_04 AC 360 ms
21,616 KB
testcase_05 AC 349 ms
21,740 KB
testcase_06 AC 361 ms
21,604 KB
testcase_07 AC 382 ms
21,680 KB
testcase_08 AC 41 ms
21,960 KB
testcase_09 AC 348 ms
21,672 KB
testcase_10 AC 349 ms
21,660 KB
testcase_11 AC 380 ms
21,620 KB
testcase_12 AC 891 ms
45,348 KB
testcase_13 AC 974 ms
45,528 KB
testcase_14 AC 948 ms
45,040 KB
testcase_15 AC 849 ms
45,112 KB
testcase_16 AC 927 ms
44,704 KB
testcase_17 AC 881 ms
44,776 KB
testcase_18 AC 948 ms
44,488 KB
testcase_19 AC 955 ms
45,136 KB
testcase_20 AC 891 ms
45,072 KB
testcase_21 AC 990 ms
44,600 KB
testcase_22 TLE -
testcase_23 AC 348 ms
21,788 KB
testcase_24 AC 350 ms
21,604 KB
testcase_25 AC 350 ms
21,664 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;
    };
  for(Int p=0;p<MAX;p++){
    Int l=0,r=MAX;
    if(calc(p,l)<m) continue;
    while(l+1<r){
      Int mid=(l+r)>>1;
      if(calc(p,mid)>=m) l=mid;
      else r=mid;
    }
    chmin(res,calc2(p,l));
  }
  cout<<res<<endl;
  return 0;
}
0