UPC-7635: Galactic Collegiate Programming Contest

7635: Galactic Collegiate Programming Contest

时间限制: 2 Sec  内存限制: 128 MB
提交: 157  解决: 51
[提交] [状态] [讨论版] [命题人:admin]

题目描述

One hundred years from now, in 2117, the International Collegiate Programming Contest (of which the NCPC is a part) has expanded significantly and it is now the Galactic Collegiate Programming Contest (GCPC).
This year there are n teams in the contest. The teams are numbered 1, 2, . . . , n, and your favorite team has number 1.
Like today, the score of a team is a pair of integers (a, b) where a is the number of solved problems and b is the total penalty of that team.
When a team solves a problem there is some associated penalty (not necessarily calculated in the same way as in the NCPC – the precise details are not important in this problem). The total penalty of a team is the sum of the penalties for the solved problems of the team. 
Consider two teams t 1 and t 2 whose scores are (a1 , b1 ) and (a2 , b2 ). The score of team t 1 is better than that of t 2 if either a1 > a2 , or if a1 = a2 and b1 < b2 . The rank of a team is k + 1 where k is the number of teams whose score is better. 
You would like to follow the performance of your favorite team. Unfortunately, the organizers of GCPC do not provide a scoreboard. Instead, they send a message immediately whenever a team solves a problem.

输入

The first line of input contains two integers n and m, where 1 ≤ n ≤ 105 is the number of teams,and 1 ≤ m ≤ 105 is the number of events.
Then follow m lines that describe the events. Each line contains two integers t and p (1 ≤ t ≤ n and 1 ≤ p ≤ 1000), meaning that team t has solved a problem with penalty p. The events are ordered by the time when they happen.

输出

Output m lines. On the i’th line, output the rank of your favorite team after the first i events have happened.

样例输入

3 4
2 7
3 5
1 6
1 9

样例输出

2
3
2
1

来源/分类

NCPC2017 

	#include<bits/stdc++.h>
	using namespace std;
	#define IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	#define rep(i,j,k) for(int i=j;i<k;i++)
	const int maxn = 100005;
	typedef long long ll;
	
	typedef struct
	{
	    int num;
	    int pent;
	}Team;
	Team team[maxn];
	
	int vis[maxn]; 
	
	queue <int> q;
	
	int main(void)
	{
	    IO 
	    memset(team,0,sizeof(team)); 
	    memset(vis,0,sizeof(vis)); 
	    int n,m;
	    scanf("%d%d",&n,&m);
	    int t,p;
	    int rank=1;
	    while(m--)
	    {
	        scanf("%d%d",&t,&p); 
	        team[t].num++;
	        team[t].pent+=p;
	        if(t!=1) {                       //不是1队的只管比1大的情况 
	            if(!vis[t])
	            if(team[t].num>team[1].num||(team[t].num==team[1].num&&team[t].pent<team[1].pent))
	                  {
	                   rank++;
	                   vis[t]=1;
	                   q.push(t);
	                  }
	        printf("%d\n",rank); 
	        continue;
	        } 
	        else{          //1队A题后重新筛选队列里比1队排名要高的队伍 
	        int len = q.size();   //必须要在循环外面确定长,不然死循环。 
	        for(int i=0;i<len;i++)  
	        {
	        	int k=q.front();
	        	q.pop();
	            if(team[k].num>team[1].num||(team[k].num==team[1].num&&team[k].pent<team[1].pent))
	                 q.push(k);
	             else
	             	 vis[k]=0;  
	                
	        }
	    }
	        rank = q.size()+1;
	        printf("%d\n",rank); 
	    }
	}

猜你喜欢

转载自blog.csdn.net/Achanss/article/details/82227751
今日推荐