码迷,mamicode.com
首页 > 其他好文 > 详细

[LibreOJ]P10114数星星

时间:2018-10-04 09:35:26      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:upd   ++   using   turn   stream   max   class   void   return   

#include<iostream>
#include<cstdio>
using namespace std;
const int maxx=100500;
int m=150000,ans[maxx],c[maxx],n;
struct data
{
    int x,y;
}a[maxx];
int bow(int x)
{
    return x&(-x);
}
void update(int x,int y)
{
    while(x<=m)
    {
        c[x]+=y;
        x+=bow(x);
    }
    return;
}
int sum(int x)
{
    int ans=0;
    while(x>0)
    {
        ans+=c[x];
        x-=bow(x);
    }
    return ans;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].x>>a[i].y;
    }
    for(int i=1;i<=n;i++)
    {
        int t=a[i].x+1;//防止树状数组内数据出现0
        update(t,1);
        int v=sum(t);//确定等级
        ans[v]++;
    }
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<endl;
    return 0;
}

[LibreOJ]P10114数星星

标签:upd   ++   using   turn   stream   max   class   void   return   

原文地址:https://www.cnblogs.com/LSWorld/p/9740773.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!