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

{
9
int m_S, m_E;
10
int m_p;
11
12
//按區(qū)間右端從大到小排序,再按左端從小到大排
13
//將左端依序插入線段樹,即將區(qū)間將大先放入,就能得出包含關(guān)系
14
bool operator < (const RANGE& other)
15
{
16
if ( m_E != other.m_E )
17
return (m_E > other.m_E);
18
19
return (m_S < other.m_S);
20
}
21
}cow[SIZE];
22
23
//線段樹
24
struct STREE
25

{
26
int m_leftPos, m_rightPos;
27
int m_left, m_right;
28
int m_ItNum; //記錄區(qū)間的左端個(gè)數(shù)
29
}tree[SIZE * 2];
30
31
int N, result[SIZE];
32
33
void BuildSTree(int& index, const int& l, const int& r)
34

{
35
int id = index;
36
tree[id].m_left = l, tree[id].m_right = r;
37
tree[id].m_ItNum = 0;
38
if ( l == r )
39
{
40
tree[id].m_leftPos = tree[id].m_rightPos = -1;
41
return ;
42
}
43
44
int mid = (l + r) >> 1;
45
46
tree[id].m_leftPos = ++index;
47
BuildSTree( index, l, mid );
48
tree[id].m_rightPos = ++index;
49
BuildSTree( index, mid + 1, r );
50
}
51
52
int Insert(const int& id, const int& s)
53

{
54
int num = 0;
55
if ( tree[id].m_left == s && tree[id].m_right == s )
56
{
57
tree[id].m_ItNum++;
58
return (tree[id].m_ItNum - 1);
59
}
60
61
int mid = (tree[id].m_left + tree[id].m_right) >> 1;
62
63
if ( s <= mid )
{
64
tree[id].m_ItNum++;
65
num += Insert(tree[id].m_leftPos, s);
66
}
67
else
{
68
num = tree[id].m_ItNum;
69
num += Insert(tree[id].m_rightPos, s);
70
}
71
72
return num;
73
}
74
75
int main()
76

{
77
freopen("1.txt", "r", stdin);
78
int i, t, maxN;
79
80
while ( true )
81
{
82
scanf("%d", &N);
83
if ( N == 0 )
84
break;
85
86
maxN = 0;
87
for ( i = 0; i < N; ++i )
88
{
89
scanf("%d %d", &cow[i].m_S, &cow[i].m_E);
90
cow[i].m_p = i;
91
if ( cow[i].m_E > maxN )
92
maxN = cow[i].m_E;
93
}
94
t = 0;
95
BuildSTree(t, 0, maxN);
96
sort(cow, cow + N);
97
98
result[cow[0].m_p] = Insert(0, cow[0].m_S);
99
for ( i = 1; i < N; ++i )
100
{
101
result[cow[i].m_p] = Insert(0, cow[i].m_S);
102
//處理區(qū)間相等的情況,插入操作還是照做,結(jié)果就為等價(jià)
103
if ( cow[i].m_E == cow[i - 1].m_E && cow[i].m_S == cow[i - 1].m_S )
104
result[cow[i].m_p] = result[cow[i - 1].m_p];
105
}
106
107
for ( i = 0; i < N - 1; ++i )
108
{
109
printf("%d ", result[i]);
110
}
111
printf("%d\n", result[i]);
112
}
113
return 0;
114
}

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

94

95

96

97

98

99

100



101

102

103

104

105

106

107

108



109

110

111

112

113

114
