标签:
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 16546 | Accepted: 5531 |
Description
Input
Output
Sample Input
3 1 2 0 3 3 4 0
Sample Output
1 0 0
Hint
Source
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define lowbit(x) (x)&(-x) 5 using namespace std; 6 7 struct Cow{ 8 int s, e; 9 int id; 10 bool operator < (const Cow& b)const 11 { 12 if(e != b.e) return e>b.e; 13 return s<b.s; 14 } 15 }cow[100005]; 16 17 int n; 18 int c[100005]; 19 int ans[100005]; 20 21 void add(int x, int val) 22 { 23 for(int i = x; i <= 100001; i += lowbit(i)) 24 c[i] += val; 25 } 26 27 int sum(int x) 28 { 29 int ret = 0; 30 for(int i = x; i > 0; i -= lowbit(i)) 31 ret += c[i]; 32 return ret; 33 } 34 35 void solve() 36 { 37 memset(c, 0, sizeof(c)); 38 memset(ans, 0, sizeof(ans)); 39 sort(cow+1, cow+n+1); 40 for(int i = 1; i <= n; ++i){ 41 if(cow[i].s == cow[i-1].s && cow[i].e == cow[i-1].e) 42 ans[cow[i].id] = ans[cow[i-1].id]; 43 else 44 ans[cow[i].id] = sum(cow[i].s); 45 add(cow[i].s, 1); 46 } 47 for(int i = 1; i < n; ++i) 48 printf("%d ", ans[i]); 49 printf("%d\n", ans[n]); 50 } 51 52 int main() 53 { 54 while(scanf("%d", &n), n){ 55 int s, e; 56 for(int i = 1; i <= n; ++i){ 57 scanf("%d%d", &s, &e); 58 cow[i].s = s+1; 59 cow[i].e = e+1; 60 cow[i].id = i; 61 } 62 solve(); 63 } 64 return 0; 65 }
标签:
原文地址:http://www.cnblogs.com/inmoonlight/p/5723409.html