結果

問題 No.2804 Fixer And Ratism
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2024-07-12 22:03:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 3,376 ms
コンパイル使用メモリ 229,860 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-12 22:03:46
合計ジャッジ時間 6,842 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 40 ms
6,944 KB
testcase_04 AC 25 ms
6,940 KB
testcase_05 AC 11 ms
6,940 KB
testcase_06 AC 74 ms
6,940 KB
testcase_07 AC 24 ms
6,940 KB
testcase_08 AC 26 ms
6,940 KB
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 21 ms
6,944 KB
testcase_11 AC 67 ms
6,940 KB
testcase_12 AC 57 ms
6,944 KB
testcase_13 AC 15 ms
6,940 KB
testcase_14 AC 56 ms
6,940 KB
testcase_15 AC 6 ms
6,940 KB
testcase_16 AC 60 ms
6,944 KB
testcase_17 AC 23 ms
6,940 KB
testcase_18 AC 100 ms
6,940 KB
testcase_19 AC 4 ms
6,944 KB
testcase_20 AC 8 ms
6,940 KB
testcase_21 AC 86 ms
6,940 KB
testcase_22 AC 5 ms
6,944 KB
testcase_23 AC 144 ms
6,940 KB
testcase_24 AC 141 ms
6,940 KB
testcase_25 AC 145 ms
6,944 KB
testcase_26 AC 143 ms
6,944 KB
testcase_27 AC 143 ms
6,940 KB
testcase_28 AC 145 ms
6,944 KB
testcase_29 AC 143 ms
6,940 KB
testcase_30 AC 143 ms
6,940 KB
testcase_31 AC 141 ms
6,944 KB
testcase_32 AC 145 ms
6,940 KB
testcase_33 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using P = pair<int, string>;
int main () {
	int N, Q;
	cin >> N >> Q;
	priority_queue<P, std::vector<P>, greater<P>> pque1, pque2 ;
	map<string, int> mpp, rte;
	int can_use = N;
	int num_b = 0;
	while (Q--) {
		int t;
		cin >> t;
		if (t == 1) {
			string s; int r;
			cin >> s >> r;
			pque1.emplace(r, s);
			num_b ++;
			mpp[s] = 1;
			rte[s] = r;
		} else if (t == 2) {
			int x;
			cin >> x;
			can_use -= x;
		} else {
			int x; string s;
			cin >> s >> x;
			if (mpp[s] != 2) {
				mpp[s] = 2;
				pque2.emplace(rte[s], s);
			}
			can_use += x;
		}
		vector<P> ret;
		while (!pque1.empty() && num_b > can_use) {
			auto [r, s] = pque1.top();
			pque1.pop();
			if (mpp[s] == 1) {
				num_b --;
				ret.emplace_back(r, s);
				mpp[s] = 0;
			}
		}
		while (!pque2.empty() && num_b > can_use) {
			auto [r, s] = pque2.top();
			pque2.pop();
			if (mpp[s] == 2) {
				num_b --;
				ret.emplace_back(r, s);
				mpp[s] = 0;
			}
		}
		sort(ret.begin(), ret.end());
		for (auto& [r1, s2] : ret) cout << s2 << endl;
	}
}
0