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. MySql登陆密码忘记了怎么办?MySQL重置root密码方法

    本文主要介绍Windows和Linux系统下忘记密码重置root密码的方法,需要的朋友可以参考下. MySQL有时候忘记了root密码是一件伤感的事.这里提供Windows 和 Linux 下的密码重 ...

  2. Discrete Log Algorithms :Baby-step giant-step 【二】

    import gmpy2 def discreteLog(g,p,a): #离散对数,求 g^x=a mod p中的x table={} sq=gmpy2.isqrt(p-1) m=gmpy2.add ...

  3. Java 层序创建和遍历二叉树

    直接上代码 package te.com; import java.util.LinkedList; import java.util.Queue; import java.util.logging. ...

  4. 颜色选择器 rgb 与16进制 颜色转换

    1. h5 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  5. es6中export和export default的区别

    export与export default均可用于导出常量.函数.文件.模块 你可以在其它文件或模块中通过import+(常量 | 函数 | 文件 | 模块)名的方式,将其导入,以便能够对其进行使用 ...

  6. Qt5标准文件对话框类

    getOpenFileName()函数返回用户选择的文件名,其函数形式如下: QString QFileDialog::getOpenFileName(QWidget *parent = Q_NULL ...

  7. QT---事件系统

    1         QT事件系统 1.1  事件的定义 QT中事件是有专门的类QEvent,常见的有键盘事件QKeyEvent.鼠标事件QMouseEvent和定时器事件QTimerEvent.例如用 ...

  8. ace后台管理系统扁平化框架

    Bootstrap ACE后台管理界面模板(扁平化) 所属分类:后台模板 文件大小:1.22 MB 阅读:236697次 下载:55929次 来源:www.daimajiayuan.com 分享到:更 ...

  9. 虚拟机vmnet0、vmnet1和vmnet8的区别

    vmnet0,实际上就是一个虚拟的网桥 vmnet0,实际上就是一个虚拟的网桥,这个网桥有很若干个端口,一个端口用于连接你的Host,一个端口用于连接你的虚拟机,他们的位置是对等的,谁也不是谁的网关. ...

  10. 最常出现的字符串 Most Common Word

    2018-10-26 00:32:05 问题描述: 问题求解: 方法一.Trie 最长出现的字符串,最容易想到的解法就是Trie树了,于是首先使用Trie树进行了实现,代码量有点大,当然了是可以A掉的 ...