标签:
题目网址: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=109331#problem/B
Description
Input
Output
Sample Input
5 1 1 5 1 7 1 3 3 5 5
Sample Output
1 2 1 1 0
Hint
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #define N 32005 using namespace std; int c[N], level[N]; int Lowbit(int t) { ///设k为t末尾0的个数,则求得为2^k=t&(t^(t-1)); return t&(t^(t-1)); } int Sum(int x) { ///统计求前面所有横坐标小于x的星星的个数; int sum = 0; while(x > 0) { sum += c[x]; x -= Lowbit(x); } return sum; } void add(int li) { ///从c[li]往跟节点一路回溯,调整这条路上的所有c[]值; while(li<=N) { c[li]++; li=li+Lowbit(li); } } int main() { int x, y, n; scanf("%d", &n); memset(c, 0, sizeof(c)); memset(level, 0, sizeof(level)); for(int i=1; i<=n; i++) { scanf("%d%d", &x, &y); ///由于坐标x可能为0,因此输入坐标要+1; add(x+1); level[Sum(x+1)-1]++;///统计level相同的个数; } for(int i=0; i<n; i++) printf("%d\n", level[i]); }
标签:
原文地址:http://www.cnblogs.com/chen9510/p/5285291.html