0
点赞
收藏
分享

微信扫一扫

【POJ_2352】Stars

题目描述

在这里插入图片描述

先按横坐标大小排序,然后通过纵坐标做树状数组就可以统计了

c o d e code code

#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

long long n, c[1001000], ans[1001000];
struct node
{
	long long x, y;
}a[1001000];

bool cmp(node x, node y)
{
	if(x.x!=y.x)
		return x.x<y.x;
	else return x.y<y.y; 
}

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

void add(long long x, long long y)
{
	for(; x<=320001; x+=lowbit(x))
		c[x]+=y;
}

long long query(long long x)
{
	long long sum=0;
	for(; x; x-=lowbit(x))
	    sum+=c[x];
	return sum;
}

int main()
{
	scanf("%lld", &n);
	for(long long i=1; i<=n; i++)
		scanf("%lld%lld", &a[i].x, &a[i].y), a[i].x++, a[i].y++;
	sort(a+1, a+1+n, cmp);
	for(long long i=1; i<=n; i++)
	{
		ans[query(a[i].y)]++;
		add(a[i].y, 1);
	}
	for(long long i=0; i<n; i++)
		printf("%lld\n", ans[i]);
	return 0; 
}
举报

相关推荐

0 条评论