标签:
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 15222 | Accepted: 5070 |
Description
Input
Output
Sample Input
3 1 2 0 3 3 4 0
Sample Output
1 0 0
Hint
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <map> 5 #include <algorithm> 6 #include <string.h> 7 using namespace std; 8 const int MAX = 100000 + 10; 9 struct node 10 { 11 int s,e; 12 int index; 13 }; 14 node a[MAX]; 15 int c[MAX],cnt[MAX]; 16 int cmp(node x,node y) 17 { 18 if(x.e == y.e) 19 return x.s < y.s; 20 return x.e > y.e; 21 } 22 int lowbit(int k) 23 { 24 return k & (-k); 25 } 26 void add (int k,int num) 27 { 28 for(int i = k; i < MAX; i += lowbit(i)) 29 c[i] += num; 30 } 31 int sum(int k) 32 { 33 int s = 0; 34 for(int i = k; i > 0; i -= lowbit(i)) 35 s += c[i]; 36 return s; 37 } 38 int main() 39 { 40 int n; 41 while(scanf("%d", &n) != EOF && n) 42 { 43 for(int i = 0; i < n; i++) 44 { 45 scanf("%d%d", &a[i].s, &a[i].e); 46 a[i].index = i; 47 } 48 sort(a,a + n,cmp); 49 memset(c,0,sizeof(c)); 50 memset(cnt,0,sizeof(cnt)); 51 cnt[a[0].index] = 0; 52 add (a[0].s + 1, 1); 53 for(int i = 1; i < n; i++) 54 { 55 if(a[i].s == a[i - 1].s && a[i].e == a[i - 1].e) 56 cnt[a[i].index] = cnt[a[i - 1].index]; 57 else 58 cnt[a[i].index] = sum(a[i].s + 1); 59 add(a[i].s + 1,1); 60 } 61 printf("%d",cnt[0]); 62 for(int i = 1; i < n; i++) 63 printf(" %d",cnt[i]); 64 printf("\n"); 65 } 66 67 return 0; 68 }
标签:
原文地址:http://www.cnblogs.com/zhaopAC/p/4977738.html