思路:先预处理出所有可能的(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;
}
443


&spm=1001.2101.3001.11974&articleId=78290342&d=1&t=3&u=63542f1a155e4f22a31c8843abe48415)

被折叠的 条评论
为什么被折叠?



