标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 41521 | Accepted: 18100 |
Description
Input
Output
Sample Input
5 1 1 5 1 7 1 3 3 5 5
Sample Output
1 2 1 1 0
Hint
Source
1 #include <cstdio> 2 #include <cstring> 3 #define lowbit(x) (x)&(-x) 4 5 int c[32005]; //树状数组 6 int ans[15005]; //存储结果 7 8 void add(int i, int val) 9 { 10 while(i <= 32001){ //注意为32001,而不是32000 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 int n; 29 scanf("%d", &n); 30 int x, y; 31 //先将两个数组清零 32 memset(c, 0, sizeof(c)); 33 memset(ans, 0, sizeof(ans)); 34 for(int i = 1; i <= n; ++i){ 35 scanf("%d%d", &x, &y); 36 ++x; //索引加1 37 ++ans[sum(x)]; //ans[]的对应处加上1 38 add(x, 1); //增加一个横坐标为x的点 39 } 40 for(int i = 0; i < n; ++i) 41 printf("%d\n", ans[i]); 42 return 0; 43 }
标签:
原文地址:http://www.cnblogs.com/inmoonlight/p/5720967.html