1
#include <cstdio>
2
#include <algorithm>
3
using namespace std;
4
5
const int SIZE = 100005;
6
7
struct RANGE
8

{
9
int m_S, m_E;
10
int m_p;
11
12
bool operator < (const RANGE& other) const
13
{
14
if ( m_E != other.m_E )
15
return (m_E > other.m_E);
16
17
return (m_S < other.m_S);
18
}
19
}cow[SIZE];
20
21
int N, result[SIZE], C[SIZE], max_N;
22
23
int LowBit( const int & k )
24

{
25
return (k & (-k));
26
}
27
28
void Modify(int num, int value)
29

{
30
while ( num <= max_N )
31
{
32
C[num] += value;
33
num += LowBit(num);
34
}
35
}
36
37
int GetSum(int num)
38

{
39
int sum = 0;
40
while ( num > 0 )
41
{
42
sum += C[num];
43
num -= LowBit(num);
44
}
45
46
return sum;
47
}
48
49
void Init()
50

{
51
for ( int i = 0; i <= max_N; ++i )
52
{
53
C[i] = 0;
54
}
55
}
56
57
int main()
58

{
59
int i;
60
61
// freopen("1.txt", "r", stdin);
62
while ( scanf("%d", &N), N != 0 )
63
{
64
max_N = 0;
65
for ( i = 0; i < N; ++i )
66
{
67
scanf("%d %d", &cow[i].m_S, &cow[i].m_E);
68
cow[i].m_S++, cow[i].m_E++;
69
cow[i].m_p = i;
70
71
if ( max_N < cow[i].m_E )
72
max_N = cow[i].m_E;
73
}
74
Init();
75
76
sort(cow, cow + N);
77
78
for ( i = 0; i < N; ++i )
79
{
80
if ( i != 0 && cow[i].m_S == cow[i - 1].m_S && cow[i].m_E == cow[i - 1].m_E )
81
result[cow[i].m_p] = result[cow[i - 1].m_p];
82
else
83
result[cow[i].m_p] = GetSum( cow[i].m_S );
84
85
Modify( cow[i].m_S, 1 );
86
}
87
88
for ( i = 0; i < N - 1; ++i )
89
printf("%d ", result[i]);
90
printf("%d\n", result[i]);
91
}
92
return 0;
93
}

2

3

4

5

6

7

8



9

10

11

12

13



14

15

16

17

18

19

20

21

22

23

24



25

26

27

28

29



30

31



32

33

34

35

36

37

38



39

40

41



42

43

44

45

46

47

48

49

50



51

52



53

54

55

56

57

58



59

60

61

62

63



64

65

66



67

68

69

70

71

72

73

74

75

76

77

78

79



80

81

82

83

84

85

86

87

88

89

90

91

92

93
