結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー Hoget157Hoget157
提出日時 2017-09-08 23:26:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,195 bytes
コンパイル時間 2,165 ms
コンパイル使用メモリ 176,804 KB
実行使用メモリ 12,396 KB
最終ジャッジ日時 2024-04-24 21:38:59
合計ジャッジ時間 5,092 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 5 ms
6,656 KB
testcase_03 AC 4 ms
6,784 KB
testcase_04 AC 5 ms
6,656 KB
testcase_05 WA -
testcase_06 AC 5 ms
6,656 KB
testcase_07 AC 5 ms
6,784 KB
testcase_08 AC 4 ms
6,656 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 4 ms
6,784 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 109 ms
12,124 KB
testcase_15 AC 117 ms
12,140 KB
testcase_16 AC 110 ms
12,084 KB
testcase_17 AC 108 ms
11,968 KB
testcase_18 AC 106 ms
11,948 KB
testcase_19 AC 114 ms
12,112 KB
testcase_20 AC 108 ms
11,984 KB
testcase_21 AC 112 ms
12,056 KB
testcase_22 WA -
testcase_23 AC 5 ms
6,784 KB
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

class BIT{
	vector<int> bit;
public:
	BIT(int siz){
		bit.resize(siz + 1,0);
	}
	void add(int i,int x){
		i++;
		while(i < bit.size()){
			bit[i] += x;
			i += i & -i;
		}
	}
	int sum(int i){
		i++;
		int s = 0;
		while(i){
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
};

typedef pair<int,int> PP;
typedef pair<int,PP> P;

signed main(){
	int n,m,kan2 = 0,kan3 = 0,mi = INF,last[100002];
	cin >> n >> m;
	BIT one(n + 5),two(n + 5);
	vector<P> vec;
	vector<int> upd[100002];
	for(int i = 0;i < 100002;i++) last[i] = -1;
	for(int i = 0;i < n;i++){
		int x,a,b;
		cin >> x >> a >> b;
		vec.push_back(mp(b,mp(x,a)));
		if(x >= 2) kan2++;
		if(x >= 3) kan3++;
	}
	sort(vec.begin(),vec.end(),greater<P>());
	for(int i = 0;i < n;i++){
		upd[vec[i].second.second].push_back(i);
		if(vec[i].second.first == 1) one.add(i,1);
		else if(vec[i].second.first == 2) two.add(i,1);
		last[vec[i].first] = i;
	}
	for(int i = 100000;i >= 0;i--) if(last[i] == -1) last[i] = last[i + 1];
	for(int i = 100001;i >= 0;i--){
		if(!upd[i].size()) continue;
		for(int v : upd[i]){
			if(vec[v].second.first == 0){
				one.add(v,1);
			}
			else if(vec[v].second.first == 1){
				one.add(v,-1);
				two.add(v,1);
				kan2++;
			}
			else if(vec[v].second.first == 2){
				two.add(v,-1);
				kan3++;
			}
			vec[v].second.first++;
		}
		int low = -1,up = 100002;
		while(up - low > 1){
			int mid = (low + up) / 2;
			if(last[mid] == -1) up = mid;
			else if(kan2 + one.sum(last[mid]) >= m) low = mid;
			else up = mid;
		}
		if(kan2 + one.sum(last[low]) < m) continue;
		mi = min(mi,kan3 + two.sum(last[low]));
	}
	cout << mi << endl;
	return 0;
}
0