結果
問題 | No.2804 Fixer And Ratism |
ユーザー |
![]() |
提出日時 | 2024-07-12 21:31:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 1,836 bytes |
コンパイル時間 | 2,727 ms |
コンパイル使用メモリ | 225,268 KB |
最終ジャッジ日時 | 2025-02-22 03:37:21 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define REP(i,n)for(int i=0;i<(n);++i) #define REP1(i,n)for(int i=1;i<=(n);++i) #define FORE(...)for(auto&&__VA_ARGS__) #define ALL(x)begin(x),end(x) #define mset(x,y)memset(x,y,sizeof x) #define pb push_back #define eb emplace_back #define V vector #define lb(x,y)(lower_bound(begin(x),end(x),y)-begin(x)) #define ub(x,y)(upper_bound(begin(x),end(x),y)-begin(x)) template<class T,class S>inline bool chmin(T&A,S B){return A>B?A=B,1:0;} template<class T,class S>inline bool chmax(T&A,S B){return A<B?A=B,1:0;} void fastIO(){ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);} using Int=long long; using Real=long double; using PII=pair<int,int>; using PLL=pair<Int,Int>; int main(){ fastIO(); int N,Q;cin>>N>>Q; V<int>A,B; map<string,int>mp; map<int,string>mp2; set<string>st; int cnt=0; V<string>ans; while(Q--){ int op;cin>>op; if(op==1){ string s; int r; cin>>s>>r; mp[s]=r; mp2[r]=s; A.pb(r); ++cnt; } if(op==2){ int x;cin>>x; N-=x; } if(op==3){ string s; int x;cin>>s>>x; N+=x; st.insert(s); B.pb(mp[s]); } if(cnt>N){ cnt=N; sort(ALL(A)); A.erase(unique(ALL(A)),end(A)); sort(ALL(B)); B.erase(unique(ALL(B)),end(B)); set<int>ss; V<int>NA,NB; int now=0; for(int i=size(B);i--;){ if(now<N){ NA.pb(B[i]); NB.pb(B[i]); ss.insert(B[i]); ++now; } } for(int i=size(A);i--;){ if(now<N&&!ss.count(A[i])){ NA.pb(A[i]); ss.insert(A[i]); ++now; } } V<int>t; REP(i,size(B))if(!ss.count(B[i])){ t.pb(B[i]); } REP(i,size(A))if(!ss.count(A[i])){ t.pb(A[i]); } sort(ALL(t)); t.erase(unique(ALL(t)),end(t)); REP(i,size(t))ans.pb(mp2[t[i]]); A=NA; B=NB; } } REP(i,size(ans))cout<<ans[i]<<"\n"; }