码迷,mamicode.com
首页 > 其他好文 > 详细

Gym - 101102C

时间:2016-12-21 23:52:12      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:i++   its   ems   tor   eof   problem   span   .net   last   

题目链接

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int data[maxn],last[maxn],ans;
struct D {
    int id;
    int sc;
    int time;
    D(int id0=0,int sc0=0,int time0=0){
        id=id0;
        sc=sc0;
        time=time0;
    }
};
bool operator < (D a,D b) {
    if(a.sc!=b.sc) return a.sc<b.sc;
    if(a.id!=b.id) return a.id>b.id;
    return a.time<b.time;
}
int main()
{
    int t,n,q,x,p;
    scanf("%d",&t);
    while(t--)
    {
        priority_queue<D> que;
        int ansid=0,anssum=0,ans=0;
        scanf("%d%d",&n,&q);
        for(int i=1;i<=n;i++) que.push(D(i,0,0));
        //printf("%d\n",que.top().id);
        memset(data,0,sizeof(data));
        memset(last,0,sizeof(last));
        ans=1;
        int ansT=0;
        for(int i=1;i<=q;i++)
        {
            scanf("%d%d",&x,&p);
            data[x]+=p;
            last[x]=i;
            while(!que.empty() && que.top().time != last[que.top().id]) que.pop();
            if(x==ans&&p<0) {
                //printf("%d %d---\n",ans,que.top().id);
                //D tmp = que.top();
                //que.pop();
                while(!que.empty() && que.top().time != last[que.top().id]) que.pop();
                //printf("%d %d---\n",ans,que.top().id);
                if(!que.empty()&&(data[ans]<que.top().sc||(data[ans]==que.top().sc && que.top().id<ans))) {
                    ansT = i;
                    ans = que.top().id;
                }
                //que.push(tmp);
            }
            else if(p>=0&&x!=ans&&(data[x]>data[ans]||(data[x]==data[ans]&&x<ans))) {
                ans = x;
                ansT = i;
            }
            que.push(D(x,data[x],i));
        }
        printf("%d\n",ansT);
    }
    return 0;
}

 

Gym - 101102C

标签:i++   its   ems   tor   eof   problem   span   .net   last   

原文地址:http://www.cnblogs.com/Ritchie/p/6209350.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!