Stars

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6581    Accepted Submission(s):
2625

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
 
题意:一个星星的地图,每个星星都有对应的等级,星星等级的计算符合以下规律:一颗星星的  左下方(包括正左方和正下方)的星星个数就是这个星星的等级
题解:先对星星的纵坐标从小到大排列,如果纵坐标相同将横坐标从小到大排列,在进行数据输入时进行对此操作的处理,
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAX 32010
using namespace std;
int sum[MAX<<2];
int pos[MAX];//记录各等级星星的个数
void pushup(int o)
{
sum[o]=sum[o<<1]+sum[o<<1|1];
}
void gettree(int o,int l,int r)
{
sum[o]=0;
if(l==r)
return ;
int mid=(l+r)>>1;
gettree(o<<1,l,mid);
gettree(o<<1|1,mid+1,r);
pushup(o);
}
void update(int o,int l,int r,int L)
{
if(l==r)
{
sum[o]+=1;
return ;
}
int mid=(l+r)>>1;
if(L<=mid)//因为建树的过程是按照星星的纵坐标从小到大建立的所以此处
//只需要考虑横坐标的情况,当横坐标小于mid对左子树进行操作
//否则对右子树进行操作。
update(o<<1,l,mid,L);
else
update(o<<1|1,mid+1,r,L);
pushup(o);
}
int find(int o,int l,int r,int L,int R)
{
if(L<=l&&R>=r)
return sum[o];
int ans=0;
int mid=(l+r)>>1;
if(L<=mid)
ans+=find(o<<1,l,mid,L,R);
if(R>mid)
ans+=find(o<<1|1,mid+1,r,L,R);
return ans;
}
int main()
{
int n,m,j,i;
int x,y;
int level;
while(scanf("%d",&n)!=EOF)
{
memset(pos,0,sizeof(pos));
gettree(1,1,MAX);
for(i=0;i<n;i++)
{
scanf("%d%d",&x,&y);
level=find(1,1,MAX,1,x+1);
pos[level]++;
update(1,1,MAX,x+1);
}
for(i=0;i<n;i++)
printf("%d\n",pos[i]);
}
return 0;
}

  

hdoj 1541 Stars【线段树单点更新+最大值维护】的更多相关文章

  1. HDU 1754 I Hate It 线段树单点更新求最大值

    题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...

  2. HDU 1166 敌兵布阵(线段树单点更新)

    敌兵布阵 单点更新和区间更新还是有一些区别的,应该注意! [题目链接]敌兵布阵 [题目类型]线段树单点更新 &题意: 第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N< ...

  3. poj 2892---Tunnel Warfare(线段树单点更新、区间合并)

    题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...

  4. HDU 1166 敌兵布阵(线段树单点更新,板子题)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  5. POJ 1804 Brainman(5种解法,好题,【暴力】,【归并排序】,【线段树单点更新】,【树状数组】,【平衡树】)

    Brainman Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10575   Accepted: 5489 Descrip ...

  6. HDU 1166 敌兵布阵(线段树单点更新,区间查询)

    描述 C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况 ...

  7. POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)

    POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...

  8. HDUOJ----1166敌兵布阵(线段树单点更新)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  9. HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)

    HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...

随机推荐

  1. 《JavaScript高级程序设计》笔记(3):传递参数

    待更新... 9.17更新: ECMAScript中所有函数的参数都是按值传递的.也就是说,把函数外部复制给函数内部的参数,就和把值从一个变量复制到另一个变量一样.基本类型值的传递如同基本类型变量的复 ...

  2. SVG

    目前SVG在国内的使用并不常见,并且关于svg的相关js库也不多,这里指出两款svg的库Snap.svg和svg.js,Snap.svg张鑫旭的博客上有关于他的使用APi http://www.zha ...

  3. dedecms插件开发教程

    这是一个很简单插件实例,通过此插件,你可以知道怎么样开发一个插件,它结构是怎么设置的,数据库,后台等.文件结构:enroll.php 文件在 plus文件下enroll.htm文件在templets/ ...

  4. html锚点

    ID模式 <h3><a href="#start">开始</a></h3> <div> 你好 <b/> &l ...

  5. 转 mysql 中sql 语句查询今天、昨天、7天、近30天、本月、上一月 数据

    转自 http://blog.csdn.net/ve_love/article/details/19685399

  6. 推送 -- error:Not get deviceToken yet

    获取不到devicetoken请检查: 1)     请检查你的pushconfig里的appkey与应用详情中是否一致 2)     bundleid有3处需要检查是否一致:a.你的应用详情中的bu ...

  7. 在mac系统安装Apache Tomcat的详细步骤

    对于Apache Tomcat 估计很多童鞋都会,那么今天就简单说下在mac上进行tomcat的安装:    第一步:下载Tomcat       这里Himi下载的tomcat version:7. ...

  8. html页面高度不同浏览器兼容性设置

    页面需要嵌套在跨域的iframe中,而页面高度不固定,需要每个页面把自己的高度获得后,通过js通知iframe调整显示. 而页面在获得自己的高度时,发现总是比预想的大.经过参考别人的博客,发现原来是w ...

  9. python学习之”迭代从入门到精通“

    在开发的过程中,假如给你一个list或者tuple,我们可以通过for循环来遍历这个list或者tuple,这种遍历我们成为迭代(Iteration).在Python中,迭代是通过for ... in ...

  10. [原博客] POJ 2505 A multiplication game 组合游戏

    题目链接题意: 有一个数p=1,甲乙两人轮流操作,每次可以把p乘2~9中的一个数,给定一个n,当一个人操作后p>=n,那么这个人赢,问先手是否必胜. 必胜状态:存在一种走法走到一个必败状态. 必 ...