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. Unity3D使用碰撞体做触发器实现简单的自己主动开门

     在游戏制作中触发器的使用很的方便也很有用. 这一张我们简介一下怎样使用一个简单的触发器来实现自己主动开门关门的效果. 首先确保你已经对门进行了动画的设置. 详细流程例如以下. 选择Window- ...

  2. Implementation of Serial Wire JTAG flash programming in ARM Cortex M3 Processors

    Implementation of Serial Wire JTAG flash programming in ARM Cortex M3 Processors The goal of the pro ...

  3. SQL Server on Linux

    https://edu.aliyun.com/course/51/lesson/list?spm=5176.8764728.aliyun-edu-course-tab.2.4YyLGD&pre ...

  4. 关于pcie的备忘

    总线驱动:深度优先统计资源,深度滞后分配资源 资源包括Bus id和内存(prefectable和non-prefectable内存) 设备驱动:包括设备驱动层和消息通信 主要是四个部分: (1)中断 ...

  5. Windows Phone本地数据库(SQLCE):9、Connection Strings(翻译) (转)

    这是“windows phone mango本地数据库(sqlce)”系列短片文章的第八篇. 为了让你开始在Windows Phone Mango中使用数据库,这一系列短片文章将覆盖所有你需要知道的知 ...

  6. Java io.netty.util.ReferenceCountUtil 代码实例

    原文:https://www.helplib.com/Java_API_Classes/article_64580 以下是展示如何使用io.netty.util.ReferenceCountUtil的 ...

  7. python测试开发django-15.查询结果转json(serializers)

    前言 django查询数据库返回的是可迭代的queryset序列,如果不太习惯这种数据的话,可以用serializers方法转成json数据,更直观 返回json数据,需要用到JsonResponse ...

  8. java.io.IOException: Attempted read from closed stream解决

    在HttpClient请求的时候,返回结果解析时出现java.io.IOException: Attempted read from closed stream. 异常,解决 原因是EntityUti ...

  9. 推荐ThinkJS

    之前在学习node.js时,写过一些例子和demo,偶尔也会有人发email问我node.js的一些问题.因为是二三年前写的东西,当时使用的第三方库和node.js的版本跟最新的可能有所不同甚至比较大 ...

  10. 【hta版】获取AppStore上架后的应用版本号

    之前写过一篇文章:获取AppStore上架后的应用版本号,那一篇文章使用node.js实现,存在的问题就是如果在没有安装node.js运行环境下是无法运行的,而且该程序依赖request模块,为了方便 ...