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. Codeforces 235E. Number Challenge DP

    dp(a,b,c,p) = sigma ( dp(a/p^i,b/p^j,c/p^k) * ( 1+i+j+k) ) 表示用小于等于p的素数去分解的结果有多少个 E. Number Challenge ...

  2. 导出文件在IE和火狐中文件名乱码问题的解决

    $ua = $_SERVER["HTTP_USER_AGENT"]; $filename = "客户数据.xls"; $encoded_filename = u ...

  3. .Net Discovery系列之十-深入理解平台机制与性能影响(上)

    转眼间<.Net Discovery>系列文章已经推出1年了,本文为该系列的第10-13篇文章,在本文中将对以前所讲的.Net平台知识做一个小小的总结与机制分析,引出并重点介绍这些机制对程 ...

  4. canvas使用1

    画直线: ? 1 2 3 4 5 6 7 8 9 10 11 var c = document.getElementById("myCanvas"); //不要忘写document ...

  5. 初学者必读:IBM长文解读人工智能、机器学习和认知计算

    转自:https://zhuanlan.zhihu.com/p/27228015?utm_source=weibo&utm_medium=social 人工智能的发展曾经经历过几次起起伏伏,近 ...

  6. 如何在Windows下运行linux shell脚本

    在工作中情况会在碰到linux下进行执行shell的脚本,而就会使用shell的脚本,但经常使用的Windows的系统,而想在Windows电脑中进行直接shell的脚本,而不用再进行学习其它的脚本语 ...

  7. 用开源项目JazzyViewPager实现ViewPager切换动画

    JazzyViewPager这个项目可以让viewpager有各种绚丽的动画,而且还可以自由扩展.但从官网下载的lib导入时会出现找不到视图的问题,不知道是不是我人品不行,所以我就自己写了lib.总之 ...

  8. 修改服务的运行权限,解决SVN Post Commit问题

    先来看一下错误现象 之前在Windows Server中安装了VirtualSVN Server,然后设置了Post Commit Hooks,在提交代码到版本库之后,将代码check到本地的一个Se ...

  9. Java NIO 的前生今世 之四 NIO Selector 详解

    Selector Selector 允许一个单一的线程来操作多个 Channel. 如果我们的应用程序中使用了多个 Channel, 那么使用 Selector 很方便的实现这样的目的, 但是因为在一 ...

  10. Windows平台Mysql使表名区分大小写

    my.ini 里面的mysqld部分   加入 lower_case_table_names=2 [mysqld] lower_case_table_names=2 port= 3306   注: 1 ...