代码:
#include<stdio.h>
#define maxn 1000005
int nn;
struct node
{
int l,r,sum;
}str[maxn];
void build(int l,int r,int n)
{
str[n].l=l;
str[n].r=r;
str[n].sum=0;
if(l==r)
return;
int temp=(l+r)/2;
build(l,temp,2*n);
build(temp+1,r,2*n+1);
}
void color(int a,int b,int n)
{
if(str[n].l==a&&str[n].r==b)
{
str[n].sum++;
return;
}
int temp=(str[n].l+str[n].r)/2;
if(b<=temp)
color(a,b,2*n);
else if(a>temp)
color(a,b,2*n+1);
else
{
color(a,temp,2*n);
color(temp+1,b,2*n+1);
}
}
void out(int n,int sum)
{
if(str[n].l==str[n].r)
{
printf("%d",sum+str[n].sum);
if(str[n].l!=nn)
printf(" ");
return;
}
out(2*n,sum+str[n].sum);
out(2*n+1,sum+str[n].sum);
}
int main()
{
while(scanf("%d",&nn),nn!=0)
{
build(1,nn,1);
for(int i=1;i<=nn;i++)
{
int a,b;
scanf("%d%d",&a,&b);
color(a,b,1);
}
out(1,0);
printf("\n");
}
}