POJ2352_Stars(段树/单点更新)
解决报告
意甲冠军:
坐标。查找在数星星的左下角每颗星星。
思考:
横轴作为间隔,已知的输入是所述第一到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;
}
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 32329 | Accepted: 14119 |
Description
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
are listed in ascending order of Y coordinate. Stars with equal Y coordinates are listed in ascending order of X coordinate.
Output
Sample Input
5
1 1
5 1
7 1
3 3
5 5
Sample Output
1
2
1
1
0
Hint
版权声明:本文博主原创文章,博客,未经同意不得转载。
POJ2352_Stars(段树/单点更新)的更多相关文章
- 计蒜客 28315.Excellent Engineers-线段树(单点更新、区间最值) (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 E)
先写这几道题,比赛的时候有事就只签了个到. 题目传送门 E. Excellent Engineers 传送门 这个题的意思就是如果一个人的r1,r2,r3中的某一个比已存在的人中的小,就把这个人添加到 ...
- ccnu-线段树-单点更新3-C
C - 单点更新3 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Des ...
- hdu-3074 Multiply game---线段树+单点更新
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3074 题目大意: 给一些数,进行点更新或者是区间计算乘积 解题思路: 裸的线段树,注意空间开大点 # ...
- hdu-4302-Holedox Eating-线段树-单点更新,有策略的单点查询
一開始实在是不知道怎么做,后来经过指导,猛然发现,仅仅须要记录某个区间内是否有值就可以. flag[i]:代表i区间内,共同拥有的蛋糕数量. 放置蛋糕的时候非常好操作,单点更新. ip:老鼠当前的位置 ...
- hdu4521 小明系列的问题——小明序列(LIS变种 (段树+单点更新解决方案))
链接: huangjing 题目:中文题目 思路: 1:这个题目假设去掉那个距离大于d的条件,那么必定是一个普通的LIS.可是加上那个条件后就变得复杂了.我用的线段树的解法. . .就是採用延迟更新的 ...
- HDU 1754 I Hate It (段树单点更新)
Problem Description 很多学校更受欢迎的习惯. 老师们真的很喜欢问.从XX XX到其中,的是多少. 这让非常多学生非常反感. 无论你喜不喜欢,如今须要你做的是,就是依照老师的要求.写 ...
- POJ - 2828 Buy Tickets (段树单点更新)
Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...
- nyoj116士兵杀死(两)段树单点更新
士兵杀敌(二) 时间限制:1000 ms | 内存限制:65535 KB 难度:5 描写叙述 南将军手下有N个士兵,分别编号1到N,这些士兵的杀敌数都是已知的. 小工是南将军手下的军师,南将军常常 ...
- HDU 1166 敌兵布阵(线段树单点更新,板子题)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
随机推荐
- WPF界面设计技巧(10)-样式的继承
原文:WPF界面设计技巧(10)-样式的继承 PS:现在我的MailMail完工了,进入内测阶段了,终于可以腾出手来写写教程了哈,关于MailMail的介绍及内测程序索取:http://www.cnb ...
- linux管理员
sudo password 添加管理员用户,设置其密码. exit 退出管理员.
- web.xml的运行顺序
整体上的顺序为 <context-param> <listener> <filter> <servlet> 往下依次运行. 当中,每一个类别内部都是按序 ...
- HDU 1171 Big Event in HDU (多重背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Socket编程实践(13) --UNIX域名协议
UNIX域名协议 UNIX域套接字与TCP相比, 在同一台主机上, UNIX域套接字更有效率, 差点儿是TCP的两倍(因为UNIX域套接字不须要经过网络协议栈,不须要打包/拆包,计算校验和,维护序号和 ...
- POJ 1287 Networking(最小生成树)
题意 给你n个点 m条边 求最小生成树的权 这是最裸的最小生成树了 #include<cstdio> #include<cstring> #include<algor ...
- ExcelHelper Excel,Export,Import
using System; using System.Collections.Generic; using System.Data; using System.Data.Odbc; using Sys ...
- Ubuntu下hadoop2.4搭建集群(单机模式)
一 .新建用户和用户组 注明:(这个步骤事实上能够不用的.只是单独使用一个不同的用户好一些) 1.新建用户组 sudo addgroup hadoop 2.新建用户 sudo adduser -in ...
- EHCache的使用
在开发高并发量,高性能的网站应用系统时,缓存Cache起到了非常重要的作用.本文主要介绍EHCache的使用,以及使用EHCache的实践经验.笔者使用过多种基于Java的开源Cache组件,其中包括 ...
- MySql之ALTER命令用法详细解读(转)
林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 本文详细解读了MySql语法中Alter命令的用法,这是一个用法比较多的语法,而且功能还是很强 ...