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. MASM 16位汇编程序几种典型的格式

    1.有名段 data segment output db 'Hello world!$' data ends code segment start: assume ds:data,cs:code mo ...

  2. 《Scala入坑笔记》缘起 3天就搞了一个 hello world

    有小伙伴向我咨询 play framework 的问题,我就想了解一下 play framework ,按照官方的文档,要使用 SBT 安装,就掉进了 SBT 的坑. 第一坑:国外仓库太慢 安装完成后 ...

  3. oracle如何去除字段的回车换行符

    oracle如何去除字段的回车换行符? 可以用trim也可以用replace.区别在于,trim处理字符串两端,而replace中间也可以处理. trim select '全世界无产者 ' || '联 ...

  4. 用百度地图API打造方便自己使用的手机地图

    有钱人咱就不说了,因为偶是个穷银--因为穷,所以去年买的Huawei C8650+到现在还在上岗,对于没有钱买好的配置的手机的童鞋来说,类似于百度,谷歌,高德等商家的地图在自己的机器上跑起来确实是有点 ...

  5. canvas 绘制图像

    结果: 代码: <!DOCTYPE html> <html> <head lang="en"> <meta charset="U ...

  6. (一)js概述

    1.    js:弱类型,动态类型,解释型的脚本语言. 2.    网景,布兰登艾奇,js和java没有关系,js的标准:ECMAscript. 3.    js组成:ECMAscript + Bom ...

  7. 快排的python实现

    快排的python实现 #python 2.7 def quick_sort(L): if len(L) <= 1: return L else: return quick_sort([lt f ...

  8. 使用jenkins并发布应用到tomcat

    jenkins的介绍及安装请自行百度,本文重点介绍如何使用jenkins,并自动发布web应用到tomcat中. 1 . 创建项目 打开jenkins --> 新建 --> 填写item名 ...

  9. CodeForces - 963D:Frequency of String (bitset暴力搞)

    You are given a string ss. You should answer nn queries. The ii-th query consists of integer kiki an ...

  10. Chrome 的书签太多如何分类整理比较好

    对于Chrome书签太多,如何进行分类整理,下面给出几种方法~ 工具/原料 电脑 Chrome浏览器 delicious.Diigo等 方法/步骤1 1.把书签中常用网站只保存LOGO,放在书签栏最前 ...