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 |
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> #include <stack> #include <queue> #include <vector> #include <map> #include <string> #include <iostream> using
namespace std; int
a[222222]; int
ret[222222]; const
int Max=33000; int
lowbit( int
x) { return
x&(-x); } int
ask( int
k) { int
sum=0; while (k>0){ sum+=a[k]; k-=lowbit(k); } return
sum; } void
change( int
x, int add) { while (x<=Max){ a[x]+=add; x+=lowbit(x); } } int
main() { int
n,x,y; while ( scanf ( "%d" ,&n)!=EOF){ memset (a,0, sizeof (a)); memset (ret,0, sizeof (ret)); for ( int
i=0;i<n;i++){ scanf ( "%d%d" ,&x,&y); change(x+1,1); int
ans=ask(x+1)-1; ret[ans]++; } for ( int
i=0;i<n;i++) printf ( "%d\n" ,ret[i]); } return
0; } |
原文地址:http://www.cnblogs.com/yigexigua/p/3773716.html