Stay Hungry,Stay Foolish!

D - Diversity of Scores

D - Diversity of Scores

https://atcoder.jp/contests/abc343/tasks/abc343_d

 

思路

准备两个map

第一个存储, 每个分数作为key, 以及 得此分数的 运动员列表 作为value

  这样,可以非常快速统计出某一时刻 所有分数总数。

第二个存储, 每个运动员作为key, 以及 此运动员当前的分数 作为value

  对于在线属于,其协助结算新的分数,并更新第一个map

 

第一个map,更新过程中,可能某个分数,之前有运动员,

但是后来运动员被移除了, 需要使用erase方法消除分数key

https://www.geeksforgeeks.org/how-to-delete-key-value-pair-from-map-in-cpp/、

 

Code

复制代码
int n, t;
map<LL, set<int>> sp; // score of players
map<int, LL> ps; // player score

int main()
{
    cin >> n >> t;
    
    for(int i=1; i<=n; i++){
        sp[0].insert(i);
        
        ps[i] = 0;
    }

    for(int i=0; i<t; i++){
        int a, b;
        cin >> a >> b;
        
        LL olds = ps[a];
        LL news = ps[a] + b;
        
        sp[olds].erase(a);
        if (sp[olds].size() == 0){
            sp.erase(sp.find(olds));
        }

        ps[a] = news;
        sp[news].insert(a);

        cout << sp.size() << endl;
    }

    return 0;
}
复制代码

 

posted @   lightsong  阅读(17)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
历史上的今天:
2022-03-02 Next.js -- SSG of React
2021-03-02 Integrating Hub with one sklearn mnist example
2015-03-02 DOM based XSS Prevention Cheat Sheet(DOM Based XSS防御检查单)
千山鸟飞绝,万径人踪灭
点击右上角即可分享
微信分享提示