結果

問題 No.2804 Fixer And Ratism
ユーザー rei
提出日時 2024-07-12 21:27:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,527 bytes
コンパイル時間 1,975 ms
コンパイル使用メモリ 129,704 KB
最終ジャッジ日時 2025-02-22 03:34:57
ジャッジサーバーID
(参考情報)
judge2 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using i8 = int8_t;
using i32 = int;
using i64 = long long;
// using i128 = __int128;
using u64 = unsigned long long;
using ll = long long;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
i64 pow(i64 j, i64 n) {
i64 res = 1;
while (n > 0) {
if (n & 1)
res *= j;
j *= j;
n >>= 1;
}
return res;
}
i64 n, q;
void _main() {
cin >> n >> q;
set<pair<i64, string>> a;
set<pair<i64, string>> b;
map<string, i64> mp;
for (i64 _ = 0; _ < q; _++) {
i64 op;
cin >> op;
if (op == 1) {
string s;
i64 r;
cin >> s >> r;
mp[s] = r;
b.insert({r, s});
} else if (op == 2) {
i64 x;
cin >> x;
n -= x;
} else {
string s;
i64 x;
cin >> s >> x;
n += x;
i64 r = mp[s];
b.erase({r, s});
a.insert({r, s});
}
vector<pair<i64, string>> del;
while (n < a.size() + b.size() && !b.empty()) {
auto [r, s] = *b.begin();
b.erase({r, s});
del.push_back({r, s});
}
while (n < a.size() + b.size() && !a.empty()) {
auto [r, s] = *a.begin();
a.erase({r, s});
del.push_back({r, s});
}
sort(del.begin(), del.end());
for (auto [r, s] : del) {
cout << s << "\n";
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0