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. linux文件组、权限等

    文件所有者.所在组合其他组  --改变用户所在组    组和在oa系统中的组差不多,用户代表的好像是个体,组有点像角色的意思.不过权限的话并不是个体从组中获得,组仅仅是一个机制,进行部分文件控制与共享 ...

  2. 字段值为NULL时的like注意事项

    null like '%%'是有问题的 mysql中应该这样写COALESCE($ZU.mobile,'') like '%%' 或者 where IsNull([table].[column],'' ...

  3. Python正则表达式使用过程中的小细节

    今天用Python写了个简单的爬虫程序,抓取虎扑篮球(nba.hupu.com)的首页内容,代码如下: #coding:gb2312 import urllib2, re webpage = urll ...

  4. [置顶] Android 关于ToolBar分分钟玩死自己?

    场景一: 今天早上十点高高兴兴的跟平时早上一样买一杯粥然后一边喝着一边去上班,步行了15分钟到了公司,然后打指纹开门,然后就愉快的写代码了,我擦,好想电脑没开机,我晕好像没带眼镜,发现最近记性不是很好 ...

  5. JS同源策略和跨域访问

    同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略,则浏览器的正常功能可能都会受到影响.可以说Web是构建在同源策略基础之上的,浏览器只 ...

  6. (一)Nginx正向代理与反向代理

    引言:身为前端开发人员来说对于Nginx的作用或许很少听到,这个东西是后端使用的,Nginx对前端而言意味着什么,有什么用呢?大白会整理出几篇文章给大家细细道来. 1.正向代理的概念 正向代理,也就是 ...

  7. Net Core网络通信

    Net Core网络通信 https://www.cnblogs.com/xxred/p/9859893.html 聊聊如何设计千万级吞吐量的.Net Core网络通信! 作者:大石头 时间:2018 ...

  8. 剑指offer-第六章面试中的各项能力(数组中只出现一次的数字)

    题目:输入一个数组,该数组中有两个只出现一次的数字,其他的数字都出现两次,输出出只出现一次的数字. 思路:首先,我们可以将这个数组分成两份,一份里面放一个只出现一次的数字.那么我们该怎么分呢?将整个数 ...

  9. 利用Github免费搭建个人主页(个人博客)

    之前闲着, 利用Github搭了个免费的个人主页. 涉及: Github注册 Github搭建博客 域名选购 绑定域名 更多 一  Github注册 在地址栏输入地址:http://github.co ...

  10. LeetCode 621. Task Scheduler

    原题链接在这里:https://leetcode.com/problems/task-scheduler/description/ 题目: Given a char array representin ...