結果
問題 | No.2804 Fixer And Ratism |
ユーザー |
|
提出日時 | 2024-07-12 22:09:07 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 144 ms / 2,000 ms |
コード長 | 1,721 bytes |
コンパイル時間 | 2,586 ms |
コンパイル使用メモリ | 135,808 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-12 22:09:36 |
合計ジャッジ時間 | 6,175 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include <iostream> #include <vector> #include <map> #include <string> #include <algorithm> using namespace std; using ll = long long; constexpr int iINF = 1'000'000'000; constexpr ll llINF = 1'000'000'000'000'000'000; int main () { int N, Q; cin >> N >> Q; map<int, string> normal, setuped; map<string, int> mp; vector<string> go_back; vector<pair<int, string>> buf; auto remove_min = [&] (map<int, string>& mp) { auto it = mp.lower_bound(-1); buf.push_back(make_pair(it->first, it->second)); mp.erase(it); }; auto clear_buf = [&] () { sort(buf.begin(), buf.end(), [&](pair<int, string>& a, pair<int, string>& b) { return a.first < b.first; }); for (auto v : buf) go_back.push_back(v.second); buf.resize(0); }; for (int i = 0; i < Q; i++) { int t; cin >> t; if (t == 1) { string s; int r; cin >> s >> r; normal[r] = s; mp[s] = r; if (N < normal.size() + setuped.size()) { remove_min(normal); } } if (t == 2) { int x; cin >> x; N -= x; while (N < normal.size() + setuped.size()) { if (0 < normal.size()) { remove_min(normal); continue; } remove_min(setuped); } } if (t == 3) { string s; int x; cin >> s >> x; N += x; setuped[mp[s]] = s; normal.erase(mp[s]); } clear_buf(); } for (auto name : go_back) { cout << name << "\n"; } }