You can solve it by tree array;
The portal:http://acm.hdu.edu.cn/showproblem.php?pid=1556
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
const int M = 100005;
int Bit[M << 1] ;
void Insert(int x,int value) {
for(int i = x ; i < M ; i += i & (-i)) {
Bit[i] += value;
}
}
int Query(int x){
int ret = 0;
for(int i = x ; i ; i -= i & (-i)) {
ret += Bit[i];
}
return ret;
}
void Deal_with(){
int n,Left,Right;
while(scanf("%d",&n),n) {
memset(Bit,0,sizeof(Bit));
for(int i = 0 ; i < n ; i ++ ) {
scanf("%d %d",&Left,&Right);
Insert(Left,1);
Insert(Right+1,-1);
}
for(int i = 1 ; i <= n ;i ++){
printf("%d",Query(i));
printf(i == n ? "\n" : " ");
}
}
}
int main(void){
//freopen("a.in","r",stdin);
Deal_with();
return 0;
}