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
(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
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
#include <iostream>
#include <cstdio>
using namespace std;
int n,x,y;
int tree[],level[];
int lowbit(int t)
{
return t&-t;
}
void update(int x,int y)
{
for(int i = x;i <= ;i += lowbit(i))
{
tree[i] += y;
}
}
int gettree(int x)
{
int ans = ;
for(int i = x;i > ;i -= lowbit(i))
{
ans += tree[i];
}
return ans;
}
int main()
{
scanf("%d",&n);
for(int i = ;i < n;i ++)
{
scanf("%d%d",&x,&y);
x ++;
level[gettree(x)] ++;
update(x,);
}
for(int i = ;i < n;i ++)
{
printf("%d\n",level[i]);
}
}
Stars的更多相关文章
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
- POJ 2352 Stars(树状数组)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30496 Accepted: 13316 Descripti ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- Java基础之在窗口中绘图——填充星型(StarApplet 2 filled stars)
Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.GeneralPath; @SuppressWarnin ...
- XidianOJ 1177 Counting Stars
题目描述 "But baby, I've been, I've been praying hard, Said, no more counting dollars We'll ...
- POJ-2352 Stars 树状数组
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ...
- hdu 1541/poj 2352:Stars(树状数组,经典题)
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- POJ 2482 Stars in Your Window 线段树扫描线
Stars in Your Window Description Fleeting time does not blur my memory of you. Can it really be 4 ...
- 2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me
Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- Stars(树状数组或线段树)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description A ...
随机推荐
- HTML5抽奖转盘
在线演示 本地下载
- ubuntu linux 1604 编译安装tesseract-ocr 4.0
主要参考官方的编译,梳理一下整个流程 Linux The build instructions for Linux also apply to other UNIX like operating sy ...
- pyqt4学习之一:搭建环境和入门
还在继续写Python小工具,想起之前用Tkinter被坑得半死,决定换个框架写UI,又想顺便了解一下qt,就学习一下pyqt4 搭建环境 win:现在安装包 http://www.riverbank ...
- Spring_属性配置细节
XML 代码: <!-- 使用构造器注入属性值的位置和参数的类型!以区分重载的构造器! --> <bean id="car1" class="com.h ...
- 分布式技术 webapi
webapi可以返回json.xml类型的数据,对于数据的增.删.改.成,提供对应的资源操作,按照请求的类型进行相应的处理,主要包括 Get(查).Post(增).Put(改).Delete(删),这 ...
- skynet启动读取配置文件浅析(skynet_main.c)
1.作为skynet的启动文件,主要完成了一些初始化和读取并存取配置文件内容的工作. 在这里只将代码读取配置文件的部分抽取出来,就算没有skynet环境,这些代码也是可以运行的,了解以后再对照源码进行 ...
- MyBatis学习(3)
MyBatis-逆向工程 Mybatis工作原理 一个MapperStatement代表一个封装改查标签的详细信息. Configuration对象保存了所有配置文件的详细信息. 总结:把配置文件的信 ...
- angularjs地址栏传参
1:路由定义参数 2.controller 3. 4.目标得到参数值
- js图片倒计时
var discountOnline = !{discountOnline} if (discountOnline) { _fresh() setInterval(_fresh, 1000); } v ...
- 基于Spring MVC实现基于form表单上传Excel文件,批量导入数据
在pom.xml中引入: <!--处理2003 excel--> <dependency> <groupId>org.apache.poi</groupId& ...