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
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。
题意:有n个星星,每个星星都有一个二维坐标,在它的左下方有几个星星有几个就代表该星星属于第几级星星,求0-n-1级星星各有多少个,举个例子:第5个星星的坐标(5,5),第一,四,二个星星在他的左下方,所以该星星属于3级星星。
题解:将星星按照横坐标从小到大,纵坐标从小到大的顺序排序,这样之后判断该星星属于第几级只需要判断在它之前有几个横坐标比他小的星星就可以了,可以用树状数组来实现前缀和的、功能。
 #include <cstdio>
#include <cstring>
const int MAXN=1e5+;
int c[MAXN],a[MAXN];//a[]是哈希数数组,用来统计每个等级的数量
int m,t;
int Lowbit(int x)
{
return x&(-x);
}
void update(int i, int x)//向上更新
{
while(i <= )
{
c[i] += x;
i += Lowbit(i);
}
}
int Getsum(int x)//向下求和
{
int sum=;
while(x>)
{
sum+=c[x];
x-=Lowbit(x);
}
return sum;
}
int main()
{
int m,x,b;
while(scanf("%d",&m)!=-)
{
int k=m;
memset(a,,sizeof());
memset(c,,sizeof());
while(k--)
{
scanf("%d%d",&x,&b);
a[Getsum(x+)]++;//用getsome()来计算在该星星前有多少个星星即是它的等级,a[]是哈希数组
update(x+,);//把该点更新
}
for(int i=; i<m; i++)
{
printf("%d\n",a[i]);
}
}
return ;
}

最新文章

  1. 入门Webpack,看这篇就够了
  2. jQuery的 delegate问题
  3. 跨浏览器兼容的HTML5视频音频播放器
  4. AVCaptureDevice
  5. Python 获取Facebook用户的Friends的爱好中的Top10
  6. UVALive 6525 Attacking rooks 二分匹配 经典题
  7. java 简单的数据增删该查
  8. 怎样用js得到当前页面的url信息方法(JS获取当前网址信息)
  9. HammerDB数据库压力工具使用简略步骤
  10. springmvc 获取request 和 java路径分隔符 在windows 和linux 下自动判断的方法
  11. sap 内表
  12. 64位windows8.1下安装 ImageMagick 总结
  13. List&lt;T&gt;.ForEach 调用异步方法的意外
  14. Spring的AOP开发入门,Spring整合Junit单元测试(基于ASpectJ的XML方式)
  15. echars柱状图修改每条柱的颜色
  16. python知识点杂记
  17. ArcFace2 #C 视频人脸比对教程
  18. Java之创建对象&gt;3.Enforce the singleton property with a private constructor or an enum type
  19. requests源码分析
  20. python-GUI,生成ssn

热门文章

  1. OC-常见归档总结
  2. 【linux】基础知识学习
  3. FlycoTabLayout 从头到脚
  4. poj3107(dfs,树形dp)
  5. Go开发Struct转换成map两种方式比较
  6. 【retina】手机上 1PX 边框
  7. js对象原型链
  8. 两种方式创建Maven项目【方式二】
  9. The method of type must override a superclass method解决方式(转)
  10. sql for 存储过程格式