結果
問題 |
No.568 じゃんじゃん 落とす 委員会
|
ユーザー |
![]() |
提出日時 | 2018-11-27 12:08:53 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 378 ms / 1,000 ms |
コード長 | 2,296 bytes |
コンパイル時間 | 2,691 ms |
コンパイル使用メモリ | 212,240 KB |
最終ジャッジ日時 | 2025-01-06 17:43:49 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#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; }