Problem: 2352 User: shu_dayang Memory: 384K Time: 157MS Language: C++ Result: Accepted #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #define MID(l,r) ((l+r) >> 1) typedef long long LL; #define MAXN 32005 using namespace std; int c[MAXN],num[MAXN]; int n; int lowbit(int x) { return x & (-x); } void update(int x) { while(x <= MAXN) { c[x]++; x += lowbit(x); } } int query(int x) { int res = 0; while(x > 0) { res += c[x]; x -= lowbit(x); } return res; } int main() { int x,y; memset(c,0,sizeof(c)); memset(num,0,sizeof(num)); scanf("%d",&n); for(int i = 1; i <= n; i++) { scanf("%d%d",&x,&y); ++x; //避免x==0因此x都加1 num[query(x)]++; update(x); } for(int i = 0; i< n; i++) printf("%d\n",num[i]); return 0; }