結果
問題 | No.2804 Fixer And Ratism |
ユーザー |
|
提出日時 | 2024-07-12 21:23:22 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 1,700 bytes |
コンパイル時間 | 3,657 ms |
コンパイル使用メモリ | 276,228 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-12 21:23:31 |
合計ジャッジ時間 | 5,607 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;template<typename T, typename Compare> struct ErasablePriorityQueue {priority_queue<T, vector<T>, Compare> q1, q2;ErasablePriorityQueue() {}ErasablePriorityQueue(initializer_list<T> ini): q1(ini.begin(), ini.end()) {}void push(T x) { q1.emplace(x); }void erase(T x) {if(!q1.empty() && q1.top() == x) {q1.pop();while(!q2.empty() && q1.top() == q2.top()) {q1.pop();q2.pop();}}else { q2.emplace(x); }}T top() const { return q1.top(); }int size() const { return q1.size() - q2.size(); }bool empty() const { return q1.empty(); }};int main() {ios::sync_with_stdio(false);cin.tie(nullptr);ll N, Q;cin >> N >> Q;vector<string> name(4001);map<string, ll> inv;vector<ll> f(4001, -1);ErasablePriorityQueue<ll, greater<ll>> q1, q2;while(Q--) {ll type;cin >> type;if(type == 1) {string s;ll r;cin >> s >> r;name[r] = s;inv[s] = r;f[r] = 0;q2.push(r);}else if(type == 2) {ll x;cin >> x;N -= x;}else {string s;ll x;cin >> s >> x;N += x;ll r = inv[s];if(!f[r]) {q2.erase(r);q1.push(r);f[r] = 1;}}vector<ll> ans;while(!q2.empty() && q1.size() + q2.size() > N) {ll t = q2.top();ans.emplace_back(t);q2.erase(t);}while(!q1.empty() && q1.size() > N) {ll t = q1.top();ans.emplace_back(t);q1.erase(t);}ranges::sort(ans);for(auto &i : ans) { cout << name[i] << "\n"; }}}