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

Hint

This problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed.
题意:给你一串坐标,找左下方的星星数
题解:树状数组,x方向处理,因为是从y方向递增的
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; int s[maxn],num[maxn]; void add(int i,int x)
{
while(i<=maxn){
s[i]+=x;
i+=i&(-i);
}
}
int sum(int i)
{
int ans=;
while(i>){
ans+=s[i];
i-=i&(-i);
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
// cout<<setiosflags(ios::fixed)<<setprecision(2);
int n,x,y;
while(cin>>n){
memset(num,,sizeof num);
memset(s,,sizeof s);
for(int i=;i<=n;i++)
{
cin>>x>>y;
int te=sum(x+);
num[te]++;
add(x+,);
}
for(int i=;i<n;i++)cout<<num[i]<<endl;
}
return ;
}

poj2352树状数组的更多相关文章

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

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

  2. [ACM_数据结构] POJ2352 [树状数组稍微变形]

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

  3. poj2352(树状数组)

    题目链接:https://vjudge.net/problem/POJ-2352 题意:在直角坐标系中给出n个点的 (x,y),(0<=x,y<=32000),定义每个点的level为(x ...

  4. POJ-2352 Stars 树状数组

    Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ...

  5. 树状数组POJ2352星星

    http://poj.org/problem?id=2352 这道题的题意对于住学者应该比较难理解,但是如果弄明白他的意思的话,你就会发现这就是赤裸裸的树状数组,哎,欺负我不懂是吧,当时读题读啦好久, ...

  6. POJ2352【树状数组】

    个人NO.1 一开始题意理解有错. 一星星左下边有N颗星星,那它的等级就是N. 一开始理解必须X,Y两个坐标都小于,后来根据样例看了一下只要左下方即可,X,Y坐标都小于等于即可,但不包括星星本身. # ...

  7. 【二维偏序】【树状数组】【权值分块】【分块】poj2352 Stars

    经典问题:二维偏序.给定平面中的n个点,求每个点左下方的点的个数. 因为 所有点已经以y为第一关键字,x为第二关键字排好序,所以我们按读入顺序处理,仅仅需要计算x坐标小于<=某个点的点有多少个就 ...

  8. poj2352 Stars【树状数组】

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

  9. POJ 3067 原来是树状数组--真的涨姿势

    题意:计划在东边的城市和西边的城市中建路,东边的点从1.....n,西边的点从1......m,求这些点连起来后有多少个交叉. PS:这个题目没有任何思路,没想到是树状数组.... 交叉出5个点 分析 ...

随机推荐

  1. 解读web服务器与php的工作原理

    最近决定重读php手册(好吧,其实之前也没怎么读,尴尬脸),既然是重读,那就从php的安装开始咯,然后被手册中出现的各种新词搞懵逼了,什么cgi.fastcgi.sapi.fpm,苍天啊,这些都是什么 ...

  2. SocketServer模块

    在利用select实现伪并发的socket博文中我们说了: 如果要实现一个server端可以和多个客户端进行通信可以使用 1.多线程 2.多进程 3.select I/O多路复用 在那篇博文中我们介绍 ...

  3. 关于压缩jar包时提示*.*没有这个文件或目录的问题以及解决办法:

    关于压缩jar包时提示.没有这个文件或目录的问题以及解决办法: 问题描述: 我在打包jar时,CMD中进入到包的上一层目录. 在命令提示符中输入 提示如下: 从提示中可知没有找到我们想要打包的clas ...

  4. BZOJ3224普通平衡树【Splay】

    3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 11751  Solved: 5013 Descriptio ...

  5. PHPCMSV9上线方法及文件权限设置

    上线步骤: a.替换代码和数据库文件内的域名b.修改cache/configs/database.php中的数据库密码c.修改cache/configs/system.php文件中的网站路径变量 'w ...

  6. Spring Hiernate整合

    Spring整合Hibernate 一.整合目标 1.由IoC容器管理Hibernate的SessionFactory2.让Hibernate使用Spring的声明式事务 二.整合步骤 先加入Hibe ...

  7. .Net EF框架的增删改查

    创建上下文对象: WordBoradEntities db = new WordBoradEntities(); 添加: //1.1创建实体对象 User uObj = new User() { uN ...

  8. CF #401 (Div. 2) C.Alyona and Spreadsheet (思维)

    题意:给你n行m列的数组,和k次的询问,问从l行到r行是否存在一个非递增的列 思路:看到这道题的数据量我们就知道直接暴力不可取,所以我们采用了预处理的方法,我们记录下来每一行的最长的非递减的列的开头的 ...

  9. C语言枚举类型(Enum)深入理解

    在实际编程中,有些数据的取值往往是有限的,只能是非常少量的整数,并且最好为每个值都取一个名字,以方便在后续代码中使用,比如一个星期只有七天,一年只有十二个月,一个班每周有六门课程等. 以每周七天为例, ...

  10. List分组 用于客服对话分组场景

    工作用可能会用到会话分组: Message是消息实体对象,里面有toId和fromId 指明接收方ID和发送方Id,通过组合形式"12-22-" 为map的key public M ...