結果

問題 No.2804 Fixer And Ratism
コンテスト
ユーザー 👑 binap
提出日時 2024-07-12 22:16:20
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.90.0)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,036 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,264 ms
コンパイル使用メモリ 230,872 KB
最終ジャッジ日時 2026-07-05 03:51:52
合計ジャッジ時間 3,174 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
In file included from /usr/include/x86_64-linux-gnu/c++/12/bits/c++allocator.h:33,
                 from /usr/include/c++/12/bits/allocator.h:46,
                 from /usr/include/c++/12/string:41,
                 from /usr/include/c++/12/bits/locale_classes.h:40,
                 from /usr/include/c++/12/bits/ios_base.h:41,
                 from /usr/include/c++/12/ios:42,
                 from /usr/include/c++/12/istream:38,
                 from /usr/include/c++/12/sstream:38,
                 from /usr/include/c++/12/complex:45,
                 from /usr/include/c++/12/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:54,
                 from main.cpp:1:
/usr/include/c++/12/bits/new_allocator.h: In instantiation of ‘void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = Query; _Args = {int&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, int&}; _Tp = Query]’:
/usr/include/c++/12/bits/alloc_traits.h:516:17:   required from ‘static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = Query; _Args = {int&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, int&}; _Tp = Query; allocator_type = std::allocator<Query>]’
/usr/include/c++/12/bits/vector.tcc:117:30:   required from ‘std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, int&}; _Tp = Query; _Alloc = std::allocator<Query>; reference = Query&]’
main.cpp:47:22:   required from here
/usr/include/c++/12/bits/new_allocator.h:186:11: error: no matching function for call to ‘Query::Query(int&, std::__cxx11::basic_string<char>&, int&)’
  186 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.

ソースコード

diff #
raw source code

#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