[学习笔记]set的使用

set默认进行升序排列,通过结构体可以改。
维护一个比主人公分数高的set 降序排列,比主人公高就进入set 比主人公低就不进去,或者在删除操作里删掉。
然后血的教训
https://blog.csdn.net/yangruibao/article/details/9040045

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
struct node{
    int t,val;
    bool operator<(const node&c)const{
        if(c.val==val){
            return t<c.t;
        }
        else{
            return val>c.val;
        }
    }
}s[maxn];
multiset<node>mot;
int main(){
    int n,m;while(~scanf("%d%d",&n,&m)){
        for(int i=0;i<=n;i++){
            s[i].val=s[i].t=0;
        }
        for(int i=1;i<=m;++i){
            int o,p;scanf("%d%d",&o,&p);
            if(o==1){
                s[1].t+=p;
                s[1].val++;
            }
            else{
                if(s[o]<s[1]){
                    mot.erase(mot.find(s[o]));
                }
                s[o].val++;
                s[o].t+=p;
                mot.insert(s[o]);
            }
            while (!mot.empty()&&!(*--mot.end()<s[1])){
                mot.erase(--mot.end());
            }
            printf("%d\n",(int)mot.size()+1);
        }
    }
}
posted @ 2018-09-15 23:45  house_cat  阅读(214)  评论(0编辑  收藏  举报