计蒜客 T3603 叫号系统 题解

原题

这道题在赛时只有 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;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值