Gym 101572G Galactic Collegiate Programming Contest(离线 树状数组)

题意:ACM比赛每个队伍的分数由(a, b)组成, a是做出题数, b是总罚时, 出题多的排名前, 相同题量罚时少排名前, 如果题量罚时都相同, 排名一样, 例如, (1, 1), (1, 1), (0, 0)三支队伍排名为1, 1, 2 现在有n支队伍, m个事件, 每个事件由(t, p)组成, 代表队伍t以罚时p做出了一题 让你输出每个事件后, 队伍1的排名


思路:先预处理出所有可能的(a, b), 离散化后就能利用树状数组维护了。分数(a, b)可以看作是一维的。


代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
int n, m;
struct node
{
    int num, pea;
    node() {}
    node(int nn, int pp): num(nn), pea(pp) {}
    bool operator < (const node &a)const
    {
        if(num == a.num) return pea < a.pea;
        else return num > a.num;
    }
}Hash[maxn], a[maxn];
int t[maxn], p[maxn], tree[maxn];

int lowbit(int x)
{
    return x&(-x);
}

void update(int pos, int val)
{
    while(pos < maxn)
    {
        tree[pos] += val;
        pos += lowbit(pos);
    }
}

int query(int pos)
{
    int res = 0;
    while(pos)
    {
        res += tree[pos];
        pos -= lowbit(pos);
    }
    return res;
}

int main(void)
{
    while(cin >> n >> m)
    {
        memset(tree, 0, sizeof(tree));
        memset(a, 0, sizeof(a));
        int cnt = 0;
        for(int i = 1; i <= m; i++)
        {
            scanf("%d%d", &t[i], &p[i]);
            a[t[i]].num++, a[t[i]].pea += p[i];
            Hash[cnt++] = node(a[t[i]].num, a[t[i]].pea);
        }
        sort(Hash, Hash+m);
        update(m+1, n);
        memset(a, 0, sizeof(a));
        for(int i = 1; i <= m; i++)
        {
            int tmp = lower_bound(Hash, Hash+m, a[t[i]])-Hash+1;
            update(tmp, -1);
            a[t[i]].num++;
            a[t[i]].pea += p[i];
            tmp = lower_bound(Hash, Hash+m, a[t[i]])-Hash+1;
            update(tmp, 1);
            int pos = lower_bound(Hash, Hash+m, a[1])-Hash+1;
            printf("%d\n", query(pos-1)+1);
        }
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值