标签:
Description
Input
Output
Sample Input
5 1 1 5 1 7 1 3 3 5 5
Sample Output
1 2 1 1 0
Hint
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 #include <vector> 6 #include <utility> 7 #include <iomanip> 8 #include <string> 9 #include <cmath> 10 #include <map> 11 12 const int MAXN = 15000 + 10; 13 const int MAX = 32000 + 10; 14 using namespace std; 15 struct DATA{ 16 int x, y; 17 bool operator < (const DATA &b)const{ 18 if (y == b.y) return x < b.x; 19 return y < b.y; 20 } 21 }data[MAXN]; 22 int n, level[MAXN]; 23 int C[MAX]; 24 25 void init(){ 26 memset(C, 0, sizeof(C)); 27 scanf("%d", &n); 28 for (int i = 1; i <= n; i++){ 29 scanf("%d%d", &data[i].x, &data[i].y); 30 } 31 sort(data + 1, data + 1 + n); 32 } 33 int lowbit(int x){return x & -x;} 34 void add(int x){ 35 while (x <= 32001){ 36 C[x]++; 37 x += lowbit(x); 38 } 39 } 40 int sum(int x){ 41 int cnt = 0; 42 while (x > 0){ 43 cnt += C[x]; 44 x -= lowbit(x); 45 } 46 return cnt; 47 } 48 void work(){ 49 memset(level, 0, sizeof(level)); 50 for (int i = 1; i <= n; i++){ 51 level[sum(data[i].x + 1)]++; 52 add(data[i].x + 1); 53 } 54 for (int i = 0; i < n; i++) printf("%d\n", level[i]); 55 } 56 57 int main(){ 58 #ifdef LOCAL 59 freopen("data.txt", "r", stdin); 60 freopen("out.txt", "w", stdout); 61 #endif 62 init(); 63 work(); 64 return 0; 65 }
标签:
原文地址:http://www.cnblogs.com/hoskey/p/4319943.html