結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー furafura
提出日時 2020-06-09 05:07:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 1,000 ms
コード長 1,975 bytes
コンパイル時間 2,055 ms
コンパイル使用メモリ 211,488 KB
実行使用メモリ 5,900 KB
最終ジャッジ日時 2023-08-28 17:03:09
合計ジャッジ時間 4,839 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
4,376 KB
testcase_01 AC 25 ms
4,380 KB
testcase_02 AC 27 ms
4,716 KB
testcase_03 AC 26 ms
4,696 KB
testcase_04 AC 25 ms
4,760 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 25 ms
4,616 KB
testcase_07 AC 26 ms
4,740 KB
testcase_08 AC 5 ms
4,612 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 28 ms
4,616 KB
testcase_12 AC 26 ms
4,376 KB
testcase_13 AC 72 ms
5,592 KB
testcase_14 AC 70 ms
5,804 KB
testcase_15 AC 64 ms
5,708 KB
testcase_16 AC 70 ms
5,588 KB
testcase_17 AC 24 ms
4,376 KB
testcase_18 AC 69 ms
5,900 KB
testcase_19 AC 71 ms
5,792 KB
testcase_20 AC 69 ms
5,404 KB
testcase_21 AC 70 ms
5,712 KB
testcase_22 AC 26 ms
4,376 KB
testcase_23 AC 25 ms
4,676 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

template<class G>
class Fenwick_tree{
	vector<G> a;
public:
	Fenwick_tree(){}
	Fenwick_tree(int n){ build(n); }
	Fenwick_tree(const vector<G>& a){ build(a); }
	void build(int n){
		a.assign(n,G{});
	}
	void build(const vector<G>& a){
		this->a=a;
		for(int i=1;i<a.size();i++) (this->a)[i+(i&-i)-1]+=(this->a)[i-1];
	}
	void add(int i,const G& val){
		for(i++;i<=a.size();i+=i&-i) a[i-1]+=val;
	}
	G sum(int l,int r)const{
		if(l==0){
			G res{};
			for(;r>0;r-=r&-r) res+=a[r-1];
			return res;
		}
		return sum(0,r)-sum(0,l);
	}
	int lower_bound(const G& val)const{
		if(val<=G{}) return 0;
		int x=0,k;
		for(k=1;k<=a.size();k<<=1);
		for(k>>=1;k>0;k>>=1) if(x+k<=a.size() && a[x+k-1]<val) val-=a[x+k-1], x+=k;
		return x;
	}
	int upper_bound(const G& val)const{
		if(val<G{}) return 0;
		int x=0,k;
		for(k=1;k<=a.size();k<<=1);
		for(k>>=1;k>0;k>>=1) if(x+k<=a.size() && a[x+k-1]<=val) val-=a[x+k-1], x+=k;
		return x;
	}
};

const int INF=1<<29;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<pair<int,int>> s[4];
	rep(i,n){
		int x,a,b; scanf("%d%d%d",&x,&a,&b);
		s[x].emplace_back(a,b);
	}

	if(s[2].size()+s[3].size()>=m){
		printf("%ld\n",s[3].size());
		return 0;
	}

	rep(x,4) sort(s[x].rbegin(),s[x].rend());

	Fenwick_tree<int> F[4];
	rep(x,4){
		F[x].build(1e5+2);
		for(auto p:s[x]) F[x].add(p.second,1);
	}

	int ans=INF,idx[3]={};
	for(int a=1e5+1;a>=0;a--){
		rep(x,3){
			while(idx[x]<s[x].size() && s[x][idx[x]].first>=a){
				F[x].add(s[x][idx[x]].second,-1);
				F[x+1].add(s[x][idx[x]].second,1);
				idx[x]++;
			}
		}

		int F2_total=F[2].sum(0,1e5+2);
		int F3_total=F[3].sum(0,1e5+2);
		if(F[1].sum(0,1e5+2)+F2_total+F3_total<m) continue;

		int lo=0,hi=1e5+2;
		while(hi-lo>1){
			int mi=(lo+hi)/2;
			if(F[1].sum(mi,1e5+2)+F2_total+F3_total>=m) lo=mi; else hi=mi;
		}
		ans=min(ans,F[2].sum(lo,1e5+2)+F3_total);
	}
	printf("%d\n",ans);

	return 0;
}
0