解决报告

意甲冠军:

坐标。查找在数星星的左下角每颗星星。

思考:

横轴作为间隔,已知的输入是所述第一到y排序再次x次序。每次添加一个点来查询点x多少分离开坐标,然后更新点。

#include <iostream>
#include <cstdio>
#include <cstring> using namespace std;
int sum[200000];
struct node {
int x,y;
} p[20000];
void push_up(int root) {
sum[root]=sum[root*2]+sum[root*2+1];
}
void update(int root,int l,int r,int p,int v) {
int mid=(l+r)/2;
if(l==r) {
sum[root]++;
return;
}
if(p<=mid)update(root*2,l,mid,p,v);
else update(root*2+1,mid+1,r,p,v);
push_up(root);
}
int q_sum(int root,int l,int r,int ql,int qr) {
if(ql>r||qr<l)return 0;
if(ql<=l&&r<=qr)return sum[root];
int mid=(l+r)/2;
return q_sum(root*2,l,mid,ql,qr)+q_sum(root*2+1,mid+1,r,ql,qr);
}
int main() {
int n,i,j,m=32000;
int _hash[20000];
scanf("%d",&n);
memset(_hash,0,sizeof(_hash));
for(i=0; i<n; i++) {
scanf("%d%d",&p[i].x,&p[i].y);
_hash[q_sum(1,0,m,0,p[i].x)]++;
update(1,0,m,p[i].x,1);
}
for(i=0; i<n; i++)
printf("%d\n",_hash[i]);
return 0;
}
Stars
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 32329   Accepted: 14119

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.

版权声明:本文博主原创文章,博客,未经同意不得转载。

POJ2352_Stars(段树/单点更新)的更多相关文章

  1. 计蒜客 28315.Excellent Engineers-线段树(单点更新、区间最值) (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 E)

    先写这几道题,比赛的时候有事就只签了个到. 题目传送门 E. Excellent Engineers 传送门 这个题的意思就是如果一个人的r1,r2,r3中的某一个比已存在的人中的小,就把这个人添加到 ...

  2. ccnu-线段树-单点更新3-C

    C - 单点更新3 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Des ...

  3. hdu-3074 Multiply game---线段树+单点更新

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3074 题目大意: 给一些数,进行点更新或者是区间计算乘积 解题思路: 裸的线段树,注意空间开大点 # ...

  4. hdu-4302-Holedox Eating-线段树-单点更新,有策略的单点查询

    一開始实在是不知道怎么做,后来经过指导,猛然发现,仅仅须要记录某个区间内是否有值就可以. flag[i]:代表i区间内,共同拥有的蛋糕数量. 放置蛋糕的时候非常好操作,单点更新. ip:老鼠当前的位置 ...

  5. hdu4521 小明系列的问题——小明序列(LIS变种 (段树+单点更新解决方案))

    链接: huangjing 题目:中文题目 思路: 1:这个题目假设去掉那个距离大于d的条件,那么必定是一个普通的LIS.可是加上那个条件后就变得复杂了.我用的线段树的解法. . .就是採用延迟更新的 ...

  6. HDU 1754 I Hate It (段树单点更新)

    Problem Description 很多学校更受欢迎的习惯. 老师们真的很喜欢问.从XX XX到其中,的是多少. 这让非常多学生非常反感. 无论你喜不喜欢,如今须要你做的是,就是依照老师的要求.写 ...

  7. POJ - 2828 Buy Tickets (段树单点更新)

    Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...

  8. nyoj116士兵杀死(两)段树单点更新

    士兵杀敌(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:5 描写叙述 南将军手下有N个士兵,分别编号1到N,这些士兵的杀敌数都是已知的. 小工是南将军手下的军师,南将军常常 ...

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

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

随机推荐

  1. eclipse 安装vrapper vim插件

    http://vrapper.sourceforge.net/update-site/stable 如果安装不上,设置下代理./window/pereference/network* - manul

  2. js面向对象编程:命名空间

    在其它语言中为了避免类和方法重名问题,都有一个类似命名空间的概念,在js中实现类似的功能吗? 能够实现,主要是借助于js中对象的概念来实现,比如:  1 在命名空间中定义方法属性 var GiantC ...

  3. Json与Java对象互转之Gson学习

    Json与Java对象互转之Gson学习 请尊重他人的劳动成果.转载请注明出处:Json与Java对象互转之Gson学习         我曾在<XML,Object,Json转换之浅析Xstr ...

  4. 大规模集群管理工具Borg

    Google的大规模集群管理工具Borg 概述 Google的Borg系统是一个集群管理工具,在它上面运行着成千上万的job,这些job来自许许多多不同的应用,并且跨越多个集群,而每个集群又由大量的机 ...

  5. JS CSS 网页 简单 右侧 悬浮

    <!--右侧效果--> <script> $().ready(function() { $(".orm").hover(function() { $(thi ...

  6. (step7.2.2)hdu 2161(Primes——判断是否是素数)

    题目大意:输入一个n,判断您是否是素数.. 解题思路:简单数论 代码如下: /* * 2161_1.cpp * * Created on: 2013年8月31日 * Author: Administr ...

  7. .NET垃圾回收笔记

    名词 垃圾收集目标 ephemeral GC 发生在Gen 0 和Gen 1 的垃圾收集 Full GC 发生Gen 2 及以上的Gen与LOH的垃圾收集 垃圾收集模式 工作站模式 GC直接发生在内存 ...

  8. Python学习路径8——Python对象2

    1.标准型运营商 1.1对象值对照 比较运算符用于如果相同类型的对象是相等.所有的内建类型的是在比较操作中支持,返回布尔比较操作值True 或 False. <span style=" ...

  9. hadoop调度程序时出现“Error opening job jar”错误

    提示出现的问题: Exception in thread "main" java.io.IOException: Error opening job jar: /home/depl ...

  10. activity点击时各种方法的区别

    用到不同方法时候某些系统有不太一样的情况: public class MainActivity extends Activity { private static String TAG = " ...