結果

問題 No.2804 Fixer And Ratism
ユーザー 👑 binapbinap
提出日時 2024-07-12 22:17:32
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 4,036 bytes
コンパイル時間 5,454 ms
コンパイル使用メモリ 324,844 KB
実行使用メモリ 13,672 KB
最終ジャッジ日時 2024-07-12 22:17:44
合計ジャッジ時間 9,833 ms
ジャッジサーバーID
(参考情報)
judge4 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 56 ms
7,360 KB
testcase_04 AC 32 ms
5,456 KB
testcase_05 AC 14 ms
5,376 KB
testcase_06 AC 90 ms
11,092 KB
testcase_07 AC 29 ms
5,376 KB
testcase_08 AC 28 ms
5,460 KB
testcase_09 AC 6 ms
5,376 KB
testcase_10 AC 22 ms
5,500 KB
testcase_11 AC 101 ms
11,408 KB
testcase_12 AC 68 ms
8,080 KB
testcase_13 AC 19 ms
5,376 KB
testcase_14 AC 67 ms
7,828 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 74 ms
11,084 KB
testcase_17 AC 30 ms
5,460 KB
testcase_18 AC 118 ms
12,092 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 10 ms
5,376 KB
testcase_21 AC 125 ms
11,620 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 199 ms
13,580 KB
testcase_24 AC 177 ms
13,520 KB
testcase_25 AC 195 ms
13,664 KB
testcase_26 AC 177 ms
13,648 KB
testcase_27 AC 183 ms
13,524 KB
testcase_28 AC 203 ms
13,544 KB
testcase_29 AC 185 ms
13,532 KB
testcase_30 AC 181 ms
13,672 KB
testcase_31 AC 182 ms
13,528 KB
testcase_32 AC 198 ms
13,556 KB
testcase_33 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef long double ld;
typedef pair<int, int> P;

ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}
template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;}
template<typename T> ostream& operator<<(ostream& os, const set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;}
template<typename T> ostream& operator<<(ostream& os, const unordered_set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;}
template<typename S, auto op, auto e> ostream& operator<<(ostream& os, const atcoder::segtree<S, op, e>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;}
template<typename S, auto op, auto e, typename F, auto mapping, auto composition, auto id> ostream& operator<<(ostream& os, const atcoder::lazy_segtree<S, op, e, F, mapping, composition, id>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;}

template<typename T> void chmin(T& a, T b){a = min(a, b);}
template<typename T> void chmax(T& a, T b){a = max(a, b);}

struct Query{
	int type;
	string name;
	int number;
};

int main(){
	int n, q;
	cin >> n >> q;
	vector<Query> querys;
	rep(i, q){
		int type;
		string name;
		int number;
		cin >> type;
		if(type == 1) cin >> name >> number;
		if(type == 2) cin >> number;
		if(type == 3) cin >> name >> number;
		querys.emplace_back(type, name, number);
	}
	vector<string> names;
	vector<int> rates;
	for(auto query : querys){
		if(query.type == 1){
			names.push_back(query.name);
			rates.push_back(query.number);
		}
	}
	int m = names.size();
	
	vector<int> fixers;
	vector<int> takers;
	int k = 0;

	vector<string> home;
	
	auto check = [&]{
		sort(fixers.begin(), fixers.end(), [&](int left, int right){return rates[left] > rates[right];});
		sort(takers.begin(), takers.end(), [&](int left, int right){return rates[left] > rates[right];});
		int n_fixer = fixers.size();
		int n_taker = takers.size();
		vector<int> candidates;
		if(n < n_fixer){
			rep(i, n_fixer - n){
				candidates.push_back(fixers.back());
				fixers.pop_back();
			}
			rep(i, n_taker){
				candidates.push_back(takers.back());
				takers.pop_back();
			}
		}else if(n < n_fixer + n_taker){
			rep(i, n_taker - (n - n_fixer)){
				candidates.push_back(takers.back());
				takers.pop_back();
			}
		}
		sort(candidates.begin(), candidates.end(), [&](int left, int right){return rates[left] < rates[right];});
		for(auto idx : candidates) home.push_back(names[idx]);
	};
	
	for(auto query : querys){
		if(query.type == 1){
			takers.push_back(k);
			k++;
			check();
		}
		if(query.type == 2){
			n -= query.number;
			check();
		}
		if(query.type == 3){
			n += query.number;
			int idx = -1;
			rep(i, m) if(query.name == names[i]) idx = i;
			auto itr = find(takers.begin(), takers.end(), idx);
			if(itr != takers.end()){
				takers.erase(itr);
				fixers.push_back(idx);
			}
		}
	}
	for(auto name : home){
		cout << name << "\n";
	}
	return 0;
}
0