题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556
#include <iostream>
#include <cstring>
#include <stdint.h>
#include <stdio.h>
using namespace std;
int bit[100010],n;
int sum(int i)
{
int s=0;
while(i>0)
{
s+=bit[i];
i-=i&-i;
}
return s;
}
void add(int i,int x)
{
while(i<=n)
{
bit[i]+=x;
i+=i&-i;
}
}
void xx(int l,int r)
{
add(l,1);
add(r+1,-1);
}
int main()
{
while(scanf("%lld",&n)!=EOF)
{
if(n==0)
return 0;
int t=n;
memset(bit,0,sizeof(bit));
while(t--)
{
int m1,m2;
scanf("%d%d",&m1,&m2);
xx(m1,m2);
}
for(int i=1;i<=n;i++)
{
if(i==n)
{
printf("%d\n",sum(i));
}
else
printf("%d ",sum(i));
}
}
return 0;
}