poj 2352 Stars

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;
}

 

posted @ 2015-07-23 14:23  杨永华  阅读(139)  评论(0编辑  收藏  举报