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<iostream>
#include<cstdio>
#include<memory.h>
using namespace std;
#define maxn 32100//是叶节点能达到的最大值多一点
int C[maxn];//从1开始编号
//--------------------------
int lowbit(int x){
return x&-x;
}
int sum(int x){
int ret=;
while(x>){
ret+=C[x];
x-=lowbit(x);
}
return ret;
}
void add(int x,int d){
while(x<=maxn){
C[x]+=d;
x+=lowbit(x);
}
}
//--------------------------
/*
给定n个点,问这一点左下角的区域的点的个数,不包括这一点
因为输入是按照y从小到达,然后是按x从小到达,且x不同
因此先出现的肯定比后出现的y小即在后出现的点之下,
因此只要把x作为树状数组下标就可以啦。然后用一个out[num]维护
个数为num的点的数量
*/
int out[maxn];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
int x,y;
int i,j;
memset(out,,sizeof(out));
memset(C,,sizeof(C));
for(i=;i<=n;i++){
scanf("%d%d",&x,&y);
out[sum(x+)]++;
add(x+,);
}
for(i=;i<n;i++){
printf("%d\n",out[i]);
}
}
return ;
}

最新文章

  1. 说一说javascript跨域和jsonp
  2. flask+sqlite3+echarts2+ajax数据可视化
  3. shell编程常用的截取字符串操作
  4. HDFS DataNode 设计实现解析
  5. 多种方法实现Loading(加载)动画效果
  6. 去除magento多店铺URL地址中的“___from_store=”
  7. Art-template模板
  8. Python基础-day2
  9. 【jQuery基础学习】05 jQuery与Ajax以及序列化
  10. hdu-Danganronpa(AC自动机)
  11. JAVA插入数据到MySql少了8小时
  12. 大数据与可靠性会碰撞出什么样的Spark?
  13. 2014年基于Raspberry Pi的5大项目
  14. nginx启动关闭
  15. Unity入门
  16. Foundation框架中日期的操作
  17. grpc 入门(一)--hello world
  18. sql操作知识点个人笔记(SQLServer篇)
  19. 跨域访问的解决方案(非HTML5的方法:JSONP)
  20. 编写优秀jQuery插件技巧

热门文章

  1. EasyUI 删除
  2. 视图的URL配置,找不到我设置的第一个Page
  3. Cookie的Domain属性
  4. android笔记:BroadcastReceiver
  5. [leetcode]560. Subarray Sum Equals K 和为K的子数组
  6. Spring框架之演示JDBC的模板类
  7. 白盒静态自动化测试工具:PMD使用指南
  8. 神奇的照片修复术,这才是 PS 的正确打开方式!
  9. Java NIO系列教程(十一) Java NIO 与 IO
  10. python数据类型4