hdu 1556

来源:互联网 发布:java接口开发 编辑:程序博客网 时间:2024/04/29 09:33

http://blog.csdn.net/geniusluzh/article/details/5900453


#include<iostream>

using namespace std;
int tree[100100];
int maxn;
void update(int k,int v)
{
while(k<=maxn)
{
tree[k]+=v;
k+=k&-k;
}
}
int read(int k)//求区间1到k的和值
{
int sum=0;
while(k>0)
{
sum+=tree[k];
k-=k&-k;
}
return sum;
}
int main()
{
int i,a,b,temp;
while(scanf("%d",&maxn)&&maxn)
{
temp=maxn;
memset(tree,0,sizeof(tree));
while(temp--)
{
scanf("%d%d",&a,&b);
update(a,1);
update(b+1,-1);
}
for(i=1;i<=maxn;i++)
{
printf("%d",read(i));
if(i!=maxn)
printf(" ");
else
printf("/n");
}
}
return 0;
}