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 ;
}

Stars(树状数组单点更新)的更多相关文章

  1. hdu 2642二维树状数组 单点更新区间查询 模板题

    二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include& ...

  2. TZOJ 2725 See you~(二维树状数组单点更新区间查询)

    描述 Now I am leaving hust acm. In the past two and half years, I learned so many knowledge about Algo ...

  3. poj3321 dfs序+树状数组单点更新 好题!

    当初听郭炜老师讲时不是很懂,几个月内每次复习树状数组必看的题 树的dfs序映射在树状数组上进行单点修改,区间查询. /* 树状数组: lowbit[i] = i&-i C[i] = a[i-l ...

  4. SPOJ - MATSUM 二维树状数组单点更新

    忘记了单点更新时要在树状数组中减去原值..wa了一发 /* 矩形求和,单点更改 */ #include<iostream> #include<cstring> #include ...

  5. 牛客小白月赛6 F 发电 树状数组单点更新 求区间乘积 模板

    链接:https://www.nowcoder.com/acm/contest/136/F来源:牛客网  HA实验是一个生产.提炼“神力水晶”的秘密军事基地,神力水晶可以让机器的工作效率成倍提升.   ...

  6. hdu 2642 二维树状数组 单点更新区间查询 模板水题

    Stars Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others) Total Subm ...

  7. hdu2642二维树状数组单点更新+区间查询

    http://acm.hdu.edu.cn/showproblem.php?pid=2642 题目大意:一个星空,二维的.上面有1000*1000的格点,每个格点上有星星在闪烁.一开始时星星全部暗淡着 ...

  8. POJ 2828 Buy Tickets(线段树 树状数组/单点更新)

    题目链接: 传送门 Buy Tickets Time Limit: 4000MS     Memory Limit: 65536K Description Railway tickets were d ...

  9. hdu2642二维树状数组单点更新

    碰到这种题一定要注意坐标是不是有序的,也要注意坐标是不是有0的,有的话需要+1处理 #include<bits/stdc++.h> using namespace std; #define ...

随机推荐

  1. SurfaceView基本使用--动态画正弦函数

    package com.zzw.TestSurfaceView; import android.content.Context; import android.graphics.Canvas; imp ...

  2. mysql中delete的表别名使用方法

    在 mapper.xml 中的 dynamicWhere 动态查询中使用了表别名,Delete 语句引用了动态查询,如下: <delete id="delete" param ...

  3. iOS编译集成linux开源c库的一些记录

    最近一个iOS项目需要使用一些Linux下面的开源c库,说是Linux的其实是跨平台的,各种Unix系统都有支持.理论上iOS来自MacOS,而MacOS其实是一种兼容的Unix系统,所以这些库应该也 ...

  4. python中的赋值与拷贝(浅拷贝与深拷贝)

    1.赋值与拷贝 直接赋值(b=a)是传引用,b改动a也会改动. a = [1, 2, 3, 4] b = a b[1] = 999 print(a, b) #[1, 999, 3, 4] [1, 99 ...

  5. How your script code be coverted into arm code and running on ios.

    Your script code is compiled into DLLs (assemblies) by the editor. When you build for iOS, these ass ...

  6. 利用Python进行文章特征提取(一)

    # 文字特征提取 词库模型(bag of words) 2016年2月26,星期五 # 1.词库表示法 In [9]: # sklearn 的 CountVectorizer类能够把文档词块化(tok ...

  7. 前端之JavaScript再次补充(干死!!)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Python之MySQLdb

    MySQLdb是用于Python链接Mysql数据库的接口,它实现了Python数据库API规范V2.0,基于MySql C API上建立的. 1. MySQLdb安装 (1)安装Mysql,参考上篇 ...

  9. MyEclipse2014快速配置Spring & Spring Testing, Spring AOP简单使用

    1.新建项目 2.右击项目,如图,利用myeclipse自动导入spring 3.在弹出的对话框中一直next到最后,在最后的页面中勾选Spring Testing,完成. 4.在src下的appli ...

  10. hibernate正向工程生成数据库

    hibernate正向工程生成数据库 hibernate.cfg.xml ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2 ...