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. SAP月末结账年结流程

    SAP月末结账年结流程 SAP月末结账操作指南 流程描述:FI期末结帐流程包括应收帐款.应付帐款.固定资产.管理会计结帐.总帐结帐等一系列结帐过程,对于年结增加了余额结转及固定资产年度改变等动作,通过 ...

  2. BZOJ 1040: [ZJOI2008]骑士(基环树dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1040 题意: 思路: 这是基环树,因为每个人只会有一个厌恶的人,所以每个节点只会有一个父亲节点,但是 ...

  3. 2018.3 江苏省计算机等级考试 C语言 编程题答案

    题目要求:给定一个数字范围,输出满足这些条件: 1.能被3整除: 2.包含数字5, 将满足的数字放在特定的数组里输出.输出这些数里5出现的个数.数字的个数. 想起来有点伤心,本来很简单的题,考试的时候 ...

  4. MD5加密与Hash加密

    一.Md5加密 MD5算法具有以下特点: 1.压缩性:任意长度的数据,算出的MD5值长度都是固定的. 2.容易计算:从原数据计算出MD5值很容易. 3.抗修改性:对原数据进行任何改动,哪怕只修改1个字 ...

  5. django表单的Widgets

    不要将Widget与表单的fields字段混淆.表单字段负责验证输入并直接在模板中使用.而Widget负责渲染网页上HTML表单的输入元素和提取提交的原始数据.widget是字段的一个内在属性,用于定 ...

  6. d3选择全部子节点,不知道class和id

    https://github.com/d3/d3-selection/issues/63 selection.selectAll("*")

  7. js判断安卓客户端或者是ios客户端,是否是微信浏览器

      代码: function xaizai() {  var u = navigator.userAgent, app = navigator.appVersion;  var isAndroid = ...

  8. C# http监听之Nancy.net

    通过winform或者是控制台应用程序监听http请求,之前使用的是微软的HttpListener,参考https://www.cnblogs.com/duanjt/p/5566336.html 然后 ...

  9. 实例对比 hibernate, spring data jpa, mybatis 选型参考

    原文: 最近重构以前写的服务,最大的一个变动是将mybatis切换为spring data jpa,切换的原因很简单,有两点:第一.它是spring的子项目能够和spring boot很好的融合,没有 ...

  10. change color

    关于DataGridView行和列的背景色-前景色设置 1.设定DataGridView全部单元格的Style   DataGridView内所有单元格的Style变更,可以使用DataGridVie ...