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;
}
#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
- hdu 1541 Stars 树状数组模板题
- HDU 1541 Stars(树状数组-水题,模板题)
- hdu 1541 Stars 树状数组水题
- HDU 2642 Stars(二维树状数组 模板题)
- HDU 1541 Stars【树状数组】
- hdu 1541 Stars (树状数组)
- HDU 1541 Stars (树状数组)
- 【树状数组】hdu 1541 Stars
- hdu-1541 Stars-----> 树状数组
- hdu 1541 树状数组 Stars
- HDU 1541 Stars 树状数组
- hdu 1541 Stars(树状数组)
- hdu 1541 Stars 树状数组
- 【HDU 1541 Stars 树状数组】
- (模板题)poj 2352 Stars(树状数组)
- Stars POJ2352(树状数组模板题)
- poj 2352 && hdu 1541 Stars (树状数组水题)
- hdu 1541(树状数组入门题 Stars)
- sqlserver 取得数据库所有表名及字段
- 初探button的titleEdgeInsets和imageEdgeInsets
- Android圆形imageview实现
- 风火轮 –动画效果:擦除、形状、轮子、随机线条、翻转远近、缩放、旋转、弹跳效果
- 总变分(Total Variation)最小化方法
- hdu 1541 Stars 树状数组模板题
- Android照片墙完整版,完美结合LruCache和DiskLruCache
- 学习selenium+python:selenium2+python2.7环境安装
- 机器学习中的数学(1)-回归(regression)、梯度下降(gradient descent)
- hdu 2159 二维完全背包
- FlappyBird开发总结(八)——MainScene场景
- 跟我一步一步学爬虫---403禁止访问(三)
- iOS中assign、copy 、retain等关键字的含义
- 解决新版ADT创建项目时出现appcompat_v7并报错