include iostream include vector include algorithm using namespace std

 1
 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
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> t(4 * 32001, 0);
void inc(int tl, int tr, int v, int i)
{
if (tl + 1 == tr)
{
t[v]++;
return;
}
int mid = (tl + tr) / 2;
if (i < mid)
inc(tl, mid, 2 * v + 1, i);
else
inc(mid, tr, 2 * v + 2, i);
t[v] = t[2*v+1] + t[2*v+2];
}
int queri(int tl, int tr, int l, int r, int v)
{
if (tl == l && tr == r)
return t[v];
int mid = (tl + tr) / 2;
if (r <= mid)
return queri(tl, mid, l, r, 2 * v + 1);
else if (l >= mid)
return queri(mid, tr, l, r, 2 * v + 2);
return (queri(tl, mid, l, mid, 2 * v + 1) + queri(mid, tr, mid, r, 2 * v + 2));
}
int main()
{
int n;
cin >> n;
vector<int> ans(n, 0);
vector<pair<int,int> > m(n);
for (int i = 0; i < n; ++i)
cin >> m[i].first >> m[i].second;
sort(m.begin(), m.end());
for (int i = 0; i < n; ++i)
{
int a = queri(0, 32001, 0, m[i].second + 1, 0);
inc(0, 32001, 0, m[i].second);
ans[a]++;
}
for (int i = 0; i < n; ++i)
cout << ans[i] << endl;
return 0;
}