这道题在赛时只有 3 % 3\% 3% 的 AC 率,其实并不是太复杂,直接用 map 的基本操作。
本来还想重载运算符排序,后来发现只需要开两个分别以 i d id id 和 u r g urg urg 为键值的 map 就可以回答询问
细节比较多,有个大坑是操作 4 中修改 i d id id 对应的 u r g urg urg 时,要记得先把原 u r g urg urg 的信息从以 u r g urg urg 为键值的 map 中删掉,操作 5 正好相反。
AC code:
#include <cstdio>
#include <map>
using namespace std;
typedef long long ll;
map<ll,ll> a,b;
ll n=0,op=0,id=0,urg=0;
signed main(){
scanf("%lld",&n);
while(n--){
scanf("%lld",&op);
if(op==1){
scanf("%lld%lld",&id,&urg);
a[id]=urg; b[urg]=id;
}
if(op==2){
if(b.size()==0) puts("error");
else{
printf("%lld\n",b.begin()->second);
a.erase(b.begin()->second); b.erase(b.begin());
}
}
if(op==3){
if(b.size()==0) puts("error");
else{
printf("%lld\n",(--b.end())->second);
a.erase((--b.end())->second); b.erase(--b.end());
}
}
if(op==4){
scanf("%lld%lld",&id,&urg);
b.erase(a[id]); a[id]=urg; b[urg]=id;
}
if(op==5){
scanf("%lld%lld",&id,&urg);
a.erase(b[urg]); a[id]=urg; b[urg]=id;
}
if(op==6){
scanf("%lld",&id);
if(a.find(id)==a.end()) puts("error");
else printf("%lld\n",a[id]);
}
if(op==7){
scanf("%lld",&urg);
if(b.find(urg)==b.end()) puts("error");
else printf("%lld\n",b[urg]);
}
}
return 0;
}