POJ 2481
http://acm.pku.edu.cn/JudgeOnline/problem?id=2481
按S的升序、其次是E的降序进行排序,然后就跟POJ 2352 Stars做法一样了~~
1 #include<stdio.h> 2 #include<iostream> 3 using namespace std; 4 5 #include<math.h> 6 #include<algorithm> 7 #include<string.h> 8 #include<stdlib.h> 9 #include<vector> 10 #include<set> 11 #include<map> 12 #include<stack> 13 #include<string> 14 #include<queue> 15 16 #define repA(p,q,i) for( int (i)=(p); (i)!=(q); ++(i) ) 17 #define repAE(p,q,i) for( int (i)=(p); (i)<=(q); ++(i) ) 18 #define repD(p,q,i) for( int (i)=(p); (i)!=(q); --(i) ) 19 #define repDE(p,q,i) for( int (i)=(p); (i)>=(q); --(i) ) 20 #define range 1010 21 #define end 100000 22 23 struct node{ 24 int ID,x,y,num; 25 node(){} 26 node(int _ID, int _x, int _y) 27 : ID(_ID), x(_x), y(_y) {} 28 }; 29 30 int a[100010]; 31 node cow[100010]; 32 int n; 33 34 bool cmp(node n1, node n2); 35 bool cmp2(node n1, node n2); 36 int lowbit(int i); 37 void update(int loc); 38 int sum(int loc); 39 40 int main() 41 { 42 while(scanf("%d",&n) != EOF ) 43 { 44 if(n==0) break; 45 46 int s,e; 47 repA(0,n,i) 48 { 49 scanf("%d%d",&s,&e); 50 cow[i] = node(i,e,s); 51 } 52 53 sort(cow, cow+n, cmp); 54 //printf("\n"); 55 //repA(0,n,i) 56 //printf("%d %d\n",cow[i].x, cow[i].y); 57 memset(a, 0, sizeof(a) ); 58 59 node u; 60 int tmp=0; 61 update(cow[0].x); 62 cow[0].num = 0; 63 repA(1,n,i) 64 { 65 if(cow[i].x == cow[i-1].x && cow[i].y == cow[i-1].y) 66 cow[i].num = cow[i-1].num; 67 else cow[i].num = i - sum(cow[i].x-1) ; 68 update(cow[i].x); 69 } 70 71 sort(cow, cow+n, cmp2); 72 73 printf("%d",cow[0].num); 74 repA(1,n,i) 75 printf(" %d",cow[i].num); 76 printf("\n"); 77 78 } 79 } 80 81 bool cmp(node n1, node n2) 82 { 83 if(n1.y != n2.y) 84 return n1.y < n2.y ; 85 else return n1.x > n2.x ; 86 } 87 88 bool cmp2(node n1, node n2) 89 { 90 return n1.ID < n2.ID ; 91 } 92 93 int lowbit(int i) 94 { 95 return i&(-i); 96 } 97 98 void update(int loc) 99 { 100 if(loc == 0) 101 { ++a[0]; return; } 102 103 for(int i=loc; i<=end; i+=lowbit(i) ) 104 a[i] += 1 ; 105 return ; 106 } 107 108 int sum(int loc) 109 { 110 int all=a[0]; 111 for(int i=loc; i>0; i-=lowbit(i) ) 112 all += a[i]; 113 return all; 114 }
To Be The Best Of Yourself