标签:os io for div amp size 测试 on
#include<stdio.h>
#include<string.h>
int l[100001];
int n;
int lowbit(int x)
{
return (x)&(-x);
}
void update(int pos,int x)
{
while(pos<=n)
{
l[pos]+=x;
pos+=lowbit(pos);
}
}
int getsum(int x)
{
int sum=0;
while(x>0)
{
sum+=l[x];
x-=lowbit(x);
}
return sum;
}
int main()
{
int i,p,q;
while(scanf("%d",&n),n)
{
memset(l,0,sizeof(l));
for(i=1;i<=n;i++)
{
scanf("%d%d",&p,&q);
update(p,1);
update(q+1,-1);
}
for(i=1;i<=n;i++)
{
if(i==n)
printf("%d",getsum(i));
else
printf("%d ",getsum(i));
}
printf("\n");
}
return 0;
}
3 1 1 2 2 3 3 3 1 1 1 2 1 3 0
1 1 1 3 2 1
标签:os io for div amp size 测试 on
原文地址:http://www.cnblogs.com/luzhongshan/p/3900747.html