Galactic Collegiate Programming Contest

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 t1 and t2 whose scores are (a1,b1) and (a2,b2). The score of team t1 is better than that of t2 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.

Input
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
Output m lines. On the i’th line, output the rank of your favorite team after the first i events have happened.

Sample Input 1 Sample Output 1
3 4
2 7
3 5
1 6
1 9
2
3
2
1

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int N = 100100;
int n, m;
int s[N], c[N];
multiset<int> a[N];
multiset<int>::iterator it, iter;
int main() {
    scanf("%d%d", &n, &m);
    int l = 1, r = 0;
    for (int i = 1; i <= m; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        if (x == 1) {
            l -= r;
            s[x]++;
            c[x] += y;
            r = 0;
            it = a[s[x]].lower_bound(c[x]);
            iter = a[s[x]].begin();
            while (iter != it) {
                r++;
                iter++;
            }
            l -= a[s[x]].size() - r;
        } else {
            if (s[x] == s[1]) {
                if (c[x] >= c[1])
                    l++;
                else
                    r--;
            }
            if (s[x] && s[x] >= s[1]) {
                if ((it = a[s[x]].find(c[x])) != a[s[x]].end())
                    a[s[x]].erase(it);
            }
            c[x] += y;
            s[x]++;
            if (s[x] == s[1] && c[x] < c[1]) {
                l++;
                r++;
            }
            a[s[x]].insert(c[x]);
        }
        printf("%d\n", l);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值