C - Bored Judge Gym - 101102C 模拟

庆祝模拟小王子xuhuang封王

Judge Bahosain was bored at ACM AmrahCPC 2016 as the winner of the contest had the first rank from the second hour until the end of the contest.

Bahosain is studying the results of the past contests to improve the problem sets he writes and make sure this won’t happen again.

Bahosain will provide you with the log file of each contest, your task is to find the first moment after which the winner of the contest doesn’t change.

The winner of the contest is the team with the highest points. If there’s more than one team with the same points, then the winner is the team with smallest team ID number.

Input
The first line of input contains a single integer T, the number of test cases.

The first line of each test case contains two space-separated integers N and Q (1 ≤ N, Q ≤ 105), the number of teams and the number of events in the log file. Teams are numbered from 1 to N.

Each of the following Q lines represents an event in the form: X P, which means team number X (1 ≤ X ≤ N) got P ( - 100 ≤ P ≤ 100, P ≠ 0) points. Note that P can be negative, in this case it represents an unsuccessful hacking attempt.

Log events are given in the chronological order.

Initially, the score of each team is zero.

Output
For each test case, if the winner of the contest never changes during the contest, print 0. Otherwise, print the number of the first event after which the winner of the contest didn’t change. Log events are numbered from 1 to Q in the given order.

Example
Input
1
5 7
4 5
3 4
2 1
1 10
4 8
3 -5
4 2
Output
5

法官Bahosain在amrahcpc 2016 ACM竞赛的胜利者从二小时直到比赛结束了,有一流的无聊。
Bahosain是研究过去比赛的结果提高习题他写道,确保这不会再次发生。
Bahosain将为您提供每个赛区的日志文件,你的任务是找到一刻之后,比赛的获胜者不改变。
比赛的获胜者是得分最高的队。如果有一个以上的团队有相同的点,那么获胜者是最小的团队ID号的团队。

first 变量名是 圣昭大佬 打错的,跟我没关系(逃——)

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<set>
#include<vector>
#include<stack>
#define lson root<<1
#define rson root<<1|1
#define MID int m = (r+l)/2;
const int inf = 0x3f3f3f3f;
const int mmax = 60000;
using namespace std;
const int MOD = 1e9+7;
int main()
{
    int t,tt;
    cin>>tt;
    int k,n,q;
    int a[111111];
    int x[111111],y[111111];
    while(tt--)
    {
        scanf("%d%d",&n,&q);
        memset(a,0,sizeof(a));
        int ss,s, fisrt,zz;
        fisrt = 1;//first默认为第一号选手,z是冠军编号
        ss = 0;//ss为当前最大分数
        t = 0;//最后时间默认为0
        for(int i=1; i<=q; i++) //q组输入
        {

            scanf("%d%d",&x[i],&y[i]);
            a[x[i]]+=y[i];
            if(x[i]==fisrt&&y[i]>=0)ss = a[ fisrt];//假如x【i】为冠军且不加分
            //则不用更新
            else if (x[i]!= fisrt)
            {
                if(y[i]<0);//假如输入的不是冠军且减分,不更新
                if(a[x[i]]>ss)//假如当前选手通过加分大于最大分,则直接更新
                {
                    ss =a[x[i]];
                    t = i;
                    fisrt = x[i];
                }
                if(a[x[i]]==ss&&x[i]< fisrt)//假如当前选手通过加分等于最大分,且编号小于当前冠军
                {
                    t = i;
                    fisrt = x[i];
                }
            }
            else
            {
                s = a[1];//s为循环过程中的分数最大值
                zz = 1;//zz为循环过程中得到冠军的编号
                for(int j=1; j<=n; j++)
                {
                    if(a[j]>s)
                    {
                        zz = j;
                        s =a[j];
                    }
                }
                ss = s;//注意一定在外边,当冠军减分却没改变其位置时,ss应当更新
                if(zz!= fisrt)//假如冠军因为减分而丢失冠军,而顺序扫描又保证编号一定最小,则更新
                {
                    fisrt = zz;

                    t = i;
                }
            }
        }
            printf("%d\n",t);

    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值