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

[ACM_数据结构] POJ2352 [树状数组稍微变形]的更多相关文章

  1. Codeforces Round #248 (Div. 2) B称号 【数据结构:树状数组】

    主题链接:http://codeforces.com/contest/433/problem/B 题目大意:给n(1 ≤ n ≤ 105)个数据(1 ≤ vi ≤ 109),当中有m(1 ≤ m ≤  ...

  2. poj2352树状数组

    Astronomers often examine star maps where stars are represented by points on a plane and each star h ...

  3. poj2352树状数组解决偏序问题

    树状数组解决这种偏序问题是很厉害的! /* 输入按照y递增,对于第i颗星星,它的level就是之前出现过的星星中,横坐标小于i的总数 */ #include<iostream> #incl ...

  4. 数据结构(树状数组):HEOI2012 采花

    [题目描述] 萧薰儿是古国的公主,平时的一大爱好是采花. 今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花.花园足够大,容纳了n朵花,花有c种颜色(用整数1-c表示),且花是排成一排的,以便 ...

  5. [poj 1533]最长上升子序列nlogn树状数组

    题目链接:http://poj.org/problem?id=2533 其实这个题的数据范围n^2都可以过,只是为了练习一下nlogn的写法. 最长上升子序列的nlogn写法有两种,一种是变形的dp, ...

  6. 【poj 3167】Cow Patterns(字符串--KMP匹配+数据结构--树状数组)

    题意:给2个数字序列 a 和 b ,问按从小到达排序后,a中的哪些子串与b的名次匹配. a 的长度 N≤100,000,b的长度 M≤25,000,数字的大小 K≤25. 解法:[思考]1.X 暴力. ...

  7. cdoj841-休生伤杜景死惊开 (逆序数变形)【线段树 树状数组】

    http://acm.uestc.edu.cn/#/problem/show/841 休生伤杜景死惊开 Time Limit: 3000/1000MS (Java/Others)     Memory ...

  8. 牛客练习赛22-E.简单数据结构1(扩展欧拉定理降幂 +树状数组)

    链接:E.简单数据结构1 题意: 给一个长为n的序列,m次操作,每次操作: 1.区间加 2.对于区间,查询 ,一直到- 请注意每次的模数不同.   题解:扩展欧拉定理降幂 对一个数p取log(p)次的 ...

  9. 「BZOJ1537」Aut – The Bus(变形Dp+线段树/树状数组 最优值维护)

    网格图给予我的第一反应就是一个状态 f[i][j] 表示走到第 (i,j) 这个位置的最大价值. 由于只能往下或往右走转移就变得显然了: f[i][j]=max{f[i-1][j], f[i][j-1 ...

随机推荐

  1. 本地Maven库添加SQLServer2012 sqljdbc4.jar

    最近又开始搞Java项目了,学习下maven用法(ant时代真的过去了啊?) 选了个国内的小框架来做,有个小需求,客户需要用牛逼哄哄的SQLServer,新版的比如SQLServer2012的sqlj ...

  2. 将2020年交期的PR回写出来了

    OUT_pr表中的交期为2020年和2019年,不应该 回写的PR却回写出来了 优化如下:

  3. thymeleaf从session中获取数据

    <input th:value="${session.value1}" />

  4. sql server 数据库学习

    http://m.blog.csdn.net/anxpp/article/details/51295020

  5. cmd命令 从C盘转到D盘

        点开始 点运行.输入 CMD 回车.进入DOS提示符状态下.输入 cd\ 回车 表示进入 c:\> 也就是C盘根目录下.输入d: 回车 是进入D盘当前目录,并不一定是根目录.然后cd\ ...

  6. Python bin() 函数

    Python bin() 函数  Python 内置函数 描述 bin() 返回一个整数 int 或者长整数 long int 的二进制表示. 语法 以下是 bin() 方法的语法: bin(x) 参 ...

  7. Golang实现一个密码生成器

    小地鼠防止有人偷他的果实,在家里上了一把锁.这个锁怎么来的呢?请往下看.. package main import ( "flag" "fmt" "m ...

  8. linux下添加用户并赋予root权限

    1.添加用户,首先用adduser命令添加一个普通用户,命令如下: #adduser tommy //添加一个名为tommy的用户#passwd tommy   //修改密码Changing pass ...

  9. mysql contact_ws函数 字符串被截断问题

    contact函数默认有字符串长度限制,解决方法:SET group_concat_max_len = 20000这个参数设置一下就好了

  10. jstl标签详解 (转载)

    JSLT标签库,是日常开发经常使用的,也是众多标签中性能最好的.把常用的内容,放在这里备份一份,随用随查.尽量做到不用查,就可以随手就可以写出来.这算是Java程序员的基本功吧,一定要扎实. JSTL ...