hdu 1541 Stars 树状数组模板题

来源:互联网 发布:服装cad制版软件 编辑:程序博客网 时间:2024/06/08 05:13
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int  maxn=15010;
const int maxlen=32010;
int tree[4*maxn];
int lowbit(int n)
{
    return (n&-n);
}
int getsum(int i)
{
    int sum=0;
    while(i>0)
    {
        sum+=tree[i];
        i-=lowbit(i);
    }
    return sum;
}
void update(int i,int dx)
{
    while(i<=maxlen)
    {
        tree[i]+=dx;
        i+=lowbit(i);
    }
}
int main()
{
    int n;
    int x,y;int i;
    int ans[maxn];
    while(scanf("%d",&n)!=EOF)
    {
        memset(ans,0,sizeof(ans));
        memset(tree,0,sizeof(tree));
        for(i=0;i<n;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            x++;
            ans[getsum(x)]++;
            update(x,1);
        }
        for(i=0;i<n;i++)
        printf("%d\n",ans[i]);
    }
    return 0;
}





































0 0