結果

問題 No.2804 Fixer And Ratism
ユーザー shobonvipshobonvip
提出日時 2024-07-12 21:32:27
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 2,170 bytes
コンパイル時間 5,069 ms
コンパイル使用メモリ 289,016 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-12 21:32:36
合計ジャッジ時間 8,654 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	int n, q; cin >> n >> q;
	map<string,int> buin_rating;
	set<string> now_buin;
	map<string,int> premium;

	vector<string> ans;
	auto shori = [&]() -> void {
		if ((int)now_buin.size() < n) return;
		vector<pair<ll,string>> yusen;
		for(string s:now_buin){
			if(premium[s] == 1){
				yusen.push_back(pair(5000+buin_rating[s], s));
			}else{
				yusen.push_back(pair(buin_rating[s],s));
			}
		}
		sort(yusen.begin(), yusen.end());
		
		vector<pair<ll,string>> stak;
		int nozoku = (int)now_buin.size() - n;
		rep(i,0,nozoku){
			stak.push_back(pair(buin_rating[yusen[i].second], yusen[i].second));
		}
		sort(stak.begin(), stak.end());
		rep(i,0,nozoku){
			ans.push_back(stak[i].second);
			now_buin.erase(stak[i].second);
		}

		return;
	};

	while(q--){
		int t; cin >> t;
		if (t == 1){
			string s; cin >> s;
			now_buin.insert(s);
			int r; cin >> r;
			buin_rating[s] = r;
			shori();
		}else if(t == 2){
			int x; cin >> x;
			n -= x;
			shori();
		}else{
			assert(t == 3);
			string s; cin >> s;
			int x; cin >> x;
			n += x;
			premium[s] = 1;
			shori();
		}
	}

	for (string s: ans){cout << s << endl;}
}

0