Stars
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 53816   Accepted: 23159

Description

Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers want to know the distribution of the levels of the stars. For example, look at the map shown on the figure above. Level of the star number 5 is equal to 3 (it's formed by three stars with a numbers 1, 2 and 4). And the levels of the stars numbered by 2 and 4 are 1. At this map there are only one star of the level 0, two stars of the level 1, one star of the level 2, and one star of the level 3. 
You are to write a program that will count the amounts of the stars of each level on a given map.

Input

The first line of the input file contains a number of stars N (1<=N<=15000). The following N lines describe coordinates of stars (two integers X and Y per line separated by a space, 0<=X,Y<=32000). There can be only one star at one point of the plane. Stars are listed in ascending order of Y coordinate. Stars with equal Y coordinates are listed in ascending order of X coordinate. 

Output

The output should contain N lines, one number per line. The first line contains amount of stars of the level 0, the second does amount of stars of the level 1 and so on, the last line contains amount of stars of the level N-1.

Sample Input

5
1 1
5 1
7 1
3 3
5 5

Sample Output

1
2
1
1
0

Hint

This problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed.

Source

****这是一道树状数组的题,根据题目可知,星星位置的顺序已经排好序了,所以对于本题来说y坐标的位置没有用,只需要一个一个星星判断他们的x坐标位置即可,由于不确定级数的范围大小,所以把级数直接设为最大可能行32001。由于树状数组的角标不能是0,所以把每个坐标的x值都加一,当然也可以加别的数字,但会增大数据范围。
 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,i,j,k,u,v,ans[] ={},tree[] = {};
struct node
{
int x;
int y;
}a[];
int lowbit(int x)
{
return x & (-x);
}
void add(int l,int x)
{
while(l <= )
{
tree[l] += x;
l += lowbit(l);
}
}
int sum(int p)
{
int res = ;
while(p > )
{
res += tree[p];
p -= lowbit(p);
}
return res;
}
int main()
{
scanf("%d",&n);
for(i = ;i <= n;i++)
{
scanf("%d %d",&a[i].x,&a[i].y);
}
for(i = ;i <= n;i++)
{
u = a[i].x + ;
v = sum(u);
ans[v] += ;
add(u,);
}
for(i = ;i < n;i++)
{
printf("%d",ans[i]);
if(i != n)
printf("\n");
}
return ;
}
 

POJ 2352 数星星的更多相关文章

  1. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

  2. codev 2147 数星星

    2147 数星星 http://codevs.cn/problem/2147/ 题目描述 Description 小明是一名天文爱好者,他喜欢晚上看星星.这天,他从淘宝上买下来了一个高级望远镜.他十分 ...

  3. 题解西电OJ (Problem 1008 - 数星星)

    题目内容: Description “不要问我太阳有多高 我会告诉你我有多真 不要问我星星有几颗 我会告诉你很多很多” 一天Qinz和wudired在天上数星星,由于星星可以排列成一条直线,他们比赛看 ...

  4. 一本通1536数星星 Stars

    1536:[例 2]数星星 Stars 时间限制: 256 ms         内存限制: 65536 KB [题目描述] 原题来自:Ural 1028 天空中有一些星星,这些星星都在不同的位置,每 ...

  5. codevs 2147 数星星

    2147 数星星 http://codevs.cn/problem/2147/ 题目描述 Description 小明是一名天文爱好者,他喜欢晚上看星星.这天,他从淘宝上买下来了一个高级望远镜.他十分 ...

  6. codevs——2147 数星星

    2147 数星星  时间限制: 3 s  空间限制: 64000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 小明是一名天文爱好者,他喜欢晚上看星星 ...

  7. codevs2147数星星(哈希)

    2147 数星星  时间限制: 3 s  空间限制: 64000 KB  题目等级 : 钻石 Diamond   题目描述 Description 小明是一名天文爱好者,他喜欢晚上看星星.这天,他从淘 ...

  8. 大红数星星 图论 XD网络赛

    问题 A: 大红数星星 时间限制: 3 Sec  内存限制: 128 MB提交: 1066  解决: 67[提交][状态][讨论版] 题目描述 “三角形十分的美丽,相信大家小学就学过三角形具有稳定性, ...

  9. POJ 2352 Stars(线段树)

    题目地址:id=2352">POJ 2352 今天的周赛被虐了. . TAT..线段树太渣了..得好好补补了(尽管是从昨天才開始学的..不能算补...) 这题还是非常easy的..维护 ...

随机推荐

  1. jquery 重要知识点总结

    jquery 重要知识点总结1.一组标签用一个ul来管理,每一个标签是ul中的一个li:标签下面的内容就是用div来管理2.跟在浮动元素(float)之后的元素会围绕着浮动元素,如果不希望有这种围绕, ...

  2. latex建立参考文献的超链接

    在Latex生成的pdf文档中建立超链接(如从正文到参考文献,从目录到相应内容,从页码编号到实际页面等),有利于读者快速定位当前阅读的信息. 如何在生成的pdf文件中包含超链接呢?需要注意一下两点: ...

  3. 【Django】【环境配置】Mac

    mysql环境配置:http://www.cnblogs.com/chenmo-xpw/p/6102933.html

  4. JQ遇到$(‘.xxx’).attr(‘display’)一直返回undefined

    jq attr && jq css 1.1 attr() 方法设置或返回被选元素的属性值 我们就题目遇到的问题做一个测试 //html <div class="div1 ...

  5. _itemmod_nopatch、_itemmod_nopatch_level、_itemmod_nopatch_spell、_itemmod_nopatch_src、_itemmod_nopatch_stat、_itemmod_nopatch_stat_prefix

    原始物品(_itemmod_nopatch中Entry)需要能够装备 该功能产生的新物品不需要制作dbc 尽量避免配置主动技能(_itemmod_nopatch_spell) _itemmod_nop ...

  6. 力扣(LeetCode)7.整数反转

    给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 输出: ...

  7. AD原理图统一命名

    1 Tools->Annotate Schematics 调出统一命名窗口 2 勾选要统一命名的原理图 3 Update Changes List 4 Accept Changes(creat ...

  8. lua中的闭包概念的学习笔记

    1.闭包的由来: 个人理解,lua中之所以出现闭包的概念,完全是因为lua中允许函数的嵌套定义,并且在内嵌函数中使用了外包函数中定义的局部变量,例如c.c#就不允许函数的嵌套定义(但是允许函数的嵌套调 ...

  9. java8新特性: lambda表达式:直接获得某个list/array/对象里面的字段集合

    java8新特性: lambda表达式:直接获得某个list/array/对象里面的字段集合 比如,我有一张表: entity Category.java service CategoryServic ...

  10. 扩大了一个逻辑卷,resize2fs 保错:没有这个超级块

    检查发现,文件系统类型是xfs,应该使用 xfs_growfs命令刷新文件系统