Problem 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
 
由于题目已经依照y的坐标排序。假设y同样。按x也已经排序。那么当前点进来,仅仅要找到不大于x的坐标的点的数量就能够了,等级说白了就是有0个点小于x的坐标。有一个点小于x的坐标。

。依次下去。

用线段树维护区间里点的数量。插入当前点之前顺带着计算比当前点的x小的数量。

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
using namespace std;
typedef long long LL;
const int MAX=0x3f3f3f3f;
const int maxn = 32222;
int sum[maxn<<2], ans[15005], n, x, y, t; // ans数组记录 该等级的数量
void up(int o) {
sum[o] = sum[o<<1] + sum[o<<1|1];
}
void in(int o, int l, int r) {
if(l == r) {
t += sum[o];
sum[o]++;
return ;
}
int m = (l+r) >> 1;
if(x <= m) {
in(lson);
} else {
t += sum[o<<1];
in(rson);
}
up(o);
}
int main()
{
while(~scanf("%d", &n)) {
memset(sum, 0, sizeof(sum));
memset(ans, 0, sizeof(ans));
for(int i = 1; i <= n; i++) {
scanf("%d%d", &x, &y);
t = 0;
in(1, 0, 32000);
ans[t]++;
}
for(int i = 0; i <= n-1; i++)
printf("%d\n", ans[i]);
}
return 0;
}

HDU 1541 Stars (线段树)的更多相关文章

  1. HDU - 1541 Stars 【树状数组】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1541 题意 求每个等级的星星有多少个 当前这个星星的左下角 有多少个 星星 它的等级就是多少 和它同一 ...

  2. hdu 1541 Stars(树状数组)

    题意:求坐标0到x间的点的个数 思路:树状数组,主要是转化,根据题意的输入顺序,保证了等级的升序,可以直接求出和即当前等级的点的个数,然后在把这个点加入即可. 注意:树状数组下标从1开始(下标为0的话 ...

  3. HDU 1541 Stars (树状数组)

    Problem Description Astronomers often examine star maps where stars are represented by points on a p ...

  4. hdu 4031 attack 线段树区间更新

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Subm ...

  5. hdu 4288 离线线段树+间隔求和

    Coder Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  6. hdu 3016 dp+线段树

    Man Down Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  7. hdu 1541 Stars(线段树单点更新,区间查询)

    题意:求坐标0到x间的点的个数 思路:线段树,主要是转化,根据题意的输入顺序,保证了等级的升序,可以直接求出和即当前等级的点的个数,然后在把这个点加入即可. 注意:线段树下标从1开始,所以把所有的x加 ...

  8. POJ 2352 &amp;&amp; HDU 1541 Stars (树状数组)

    一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~ ...

  9. HDU 5877 dfs+ 线段树(或+树状树组)

    1.HDU 5877  Weak Pair 2.总结:有多种做法,这里写了dfs+线段树(或+树状树组),还可用主席树或平衡树,但还不会这两个 3.思路:利用dfs遍历子节点,同时对于每个子节点au, ...

随机推荐

  1. 初探C++类模版学习笔记

    类模板 实现:在定义类的时候给它一个或多个參数,这个些參数表示不同的数据类型.                              -->抽象的类. 在调用类模板时, 指定參数, 由编译系 ...

  2. python websocket-client connection

    参考:https://pypi.python.org/pypi/websocket-client/    https://www.cnblogs.com/saryli/p/6702260.html i ...

  3. [Asp.net]web.config customErrors 如何设置?

    摘要 customErrors也经常在开发部署中看到<customErrors mode="Off" />,设置这样可以在页面上看到详细的错误信息.但也为黑客提供了攻击 ...

  4. 多用StringBuilder,少用字符串拼接

    在C#中,在处理字符串拼接的时候,使用StringBuilder的效率会比硬拼接字符串高很多.到底有多高,如下: static void Main(string[] args) { string st ...

  5. 用DELPHI 开发压缩、解压、自解压、加密

    引 言:在日常中,我们一定使用过WINZIP.WINRAR这样的出名的压缩软件,就是我们开发软件过程中不免要遇到数据加密.数据压缩的问题!本文中就这一技术问题展开探讨,同时感谢各位网友的技巧,在我每次 ...

  6. android 中theme.xml与style.xml的区别

    from://http://liangoogle.iteye.com/blog/1848448 android 中theme.xml与style.xml的区别: 相同点: 两者的定义相同. <r ...

  7. Android之关于MAC把java7改为java6的方法

    先来个草草草,某天手贱有java6升级为java7了,然后用ant打包发布,然后再一次草草草,居然有冲突勒,网上找了一堆...无果,最后想起直接在.bash_profile上配置环境试试吧,居然通了, ...

  8. 通过Selector来设置按钮enable/unable状态的样式

    我们可以用selector来配置button可用或者不可用时的背景,也可以用它来配置button不同状态下的文字颜色.下面左图是可用状态,右图是不可用状态.    一.配置按钮不同状态的背景 首先我们 ...

  9. Datagridview 在基于文本的单元格中启用换行,自动调整行高列宽

    将 DataGridViewCellStyle的 WrapMode 属性设置为 DataGridViewTriState 枚举值之一.下面的代码示例使用 System.Windows.Forms.Da ...

  10. Kubernetes中Pod的健康检查

    本文介绍 Pod 中容器健康检查相关的内容.配置方法以及实验测试,实验环境为 Kubernetes 1.11,搭建方法参考kubeadm安装kubernetes V1.11.1 集群 0. 什么是 C ...