解决报告

意甲冠军:

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

思考:

横轴作为间隔,已知的输入是所述第一到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. SVN的命令解析(感觉不错就转了)

    本文链接: http://www.php-oa.com/2008/03/12/svnminglingzailinuxxiadeshiyong.html .将文件checkout到本地目录 svn ch ...

  2. 飘逸的python - __new__、__init__、__call__傻傻分不清

    __new__: 对象的创建,是一个静态方法.第一个參数是cls.(想想也是,不可能是self,对象还没创建,哪来的self) __init__ : 对象的初始化, 是一个实例方法,第一个參数是sel ...

  3. C#区域截图——调用API截图

    原文:C#区域截图——调用API截图 前言:截图对于一个C++开发者来说无非是小菜一碟,也有朋友使用C#的 Graphics.CopyFromScreen 方法屏幕操作,作为一名整天想着用 C++ 开 ...

  4. Maven 中配置 Urlrewrite 基本配置

    1. 在maven项目的pom.xml文件里加入: <!-- URL Rewrite --> <dependency> <groupId>org.tuckey< ...

  5. 【Unity3D自学记录】利用代码改动图片属性(Inspector)

    这段时间一直都在打包资源,然后每次导入都要改图片的属性.真是麻烦,所以一直在寻找一键改动而且打包的方法. 最终让我找到了,太坑人了. 依据自己的需求改代码哦,相信大家都能看明确. 核心部分: Text ...

  6. 使用CSS3制图

    参考资料:http://blog.csdn.net/fense_520/article/details/37892507 本文非转载.为个人原创,转载请先联系博主,谢谢~ 准备: <!DOCTY ...

  7. 将Excel数据表到数据库表

    假设你有大量的数据要导入到数据库表,恐怕是没有效率的写程序,作为用于数据操纵,Excel在这方面有优势,但是,如何将其结合起来?将Excel数据表到数据库表,就是本篇博客的目的. 首先去下载MySQL ...

  8. Java EE (5) -- Java EE 6 JavaServer Faces Developer Certified Expert(1z0-896)

    Section 1: Essentials of JSF2.0 Identify the features of JSF such as Facelets, BookMarkable View, AJ ...

  9. 潜水 java类加载器ClassLoader

    类加载器(class loader)用于装载 Java 类到 Java 虚拟机中.一般来说.Java 虚拟机使用 Java 类的方式例如以下:Java 源程序(.java 文件)在经过 Java 编译 ...

  10. hadoop 提高hdfs删文件效率----hadoop删除文件流程解析

    前言 这段时间在用hdfs,由于要处理的文件比较多,要及时产出旧文件,但是发现hdfs的blocks数一直在上涨,经分析是hdfs写入的速度较快,而block回收较慢,所以分心了一下hadoop删文件 ...