标签:
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16486 Accepted Submission(s): 8203
1 #include <cstdio> 2 #include <cstring> 3 #define lowbit(x) (x)&(-x) 4 5 int n, a, b; 6 int c[100005]; 7 8 void add(int i, int val) 9 { 10 while(i <= n){ 11 c[i] += val; 12 i += lowbit(i); 13 } 14 } 15 16 int sum(int i) 17 { 18 int ret = 0; 19 while(i > 0){ 20 ret += c[i]; 21 i -= lowbit(i); 22 } 23 return ret; 24 } 25 26 int main() 27 { 28 while(scanf("%d", &n), n){ 29 memset(c, 0, sizeof(c)); 30 for(int i = 1; i <= n; ++i){ 31 scanf("%d%d", &a, &b); 32 add(a, 1); 33 add(b+1, -1); 34 } 35 for(int i = 1; i < n; ++i) 36 printf("%d ", sum(i)); 37 printf("%d\n", sum(n)); 38 } 39 return 0; 40 }
标签:
原文地址:http://www.cnblogs.com/inmoonlight/p/5721653.html