http://acm.hdu.edu.cn/showproblem.php?pid=1556

代码:

#include<iostream>
int n,c[100003];
int lowbit(int x)
{
	return x&(-x);
}
int sum(int x)
{
	int sum=0;
	while(x>0)
	{
		sum+=c[x];
		x-=lowbit(x);
	}
	return sum;
}
void inster(int x,int i)
{
	while(x<=n)
	{
		c[x]+=i;
		x+=lowbit(x);
	}
}
int main()
{
	int a,b,i;
	while(scanf("%d",&n)>0&&n)
	{
		memset(c,0,sizeof(c));
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&a,&b);
			inster(b+1,-1);
			inster(a,1);
		}
		for(i=1;i<n;i++)
			printf("%d ",sum(i));
		printf("%d\n",sum(n));
	}
	return 0;
}

 

相关文章:

  • 2022-01-30
  • 2021-05-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-10
  • 2022-12-23
  • 2021-07-15
猜你喜欢
  • 2022-12-23
  • 2021-07-12
  • 2022-01-21
  • 2022-12-23
  • 2021-07-28
  • 2021-11-15
  • 2021-09-07
相关资源
相似解决方案