Stars
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 42898   Accepted: 18664

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

Hint

This problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed.

Source

 
题意:如果一个点的左下方(包含正左和正下)有k个点,就说这个点是k级的。求出各个级别的点的个数。、
思路:将点按y升序,y相同按x升序进行排序。按照x轴建立一位树状数组。(或者将点按x升序,x相同按y升序进行排序。按照y轴建立一位树状数组)

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN=,MAXX=;
int c[MAXX];
int ans[MAXN];
int lowbit(int x)
{
return x&(-x);
}
void add(int i,int val)
{
for(i; i<=MAXX; i+=lowbit(i))
c[i]+=val;
}
int sum(int i)
{
int s=;
for(i; i>; i-=lowbit(i))
s+=c[i];
return s;
}
int main()
{
int i,n;
int x,y;
while(scanf("%d",&n)!=EOF)
{
memset(c,,sizeof(c));
memset(ans,,sizeof(ans));
for(i=; i<n; i++)
{
scanf("%d%d",&x,&y);
int temp=sum(x+);
ans[temp]++;
add(x+,);
}
for(i=; i<n; i++)
printf("%d\n",ans[i]);
}
return ;
}

树状数组

POJ 2352Stars 树状数组的更多相关文章

  1. POJ 3321 树状数组(+dfs+重新建树)

    Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 27092   Accepted: 8033 Descr ...

  2. poj 2299 树状数组求逆序数+离散化

    http://poj.org/problem?id=2299 最初做离散化的时候没太确定可是写完发现对的---由于后缀数组学的时候,,这样的思维习惯了吧 1.初始化as[i]=i:对as数组依照num ...

  3. poj 3928 树状数组

    题目中只n个人,每个人有一个ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判的ID和技能值都在两个选手之间的时候才能进行一场比赛,现在问一共能组织多少场比赛. 由于排完序之后,先插入的一定 ...

  4. POJ 2299 树状数组+离散化求逆序对

    给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数 ...

  5. poj 2299 树状数组求逆序对数+离散化

    Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 54883   Accepted: 20184 ...

  6. poj 2182 树状数组

    这题对于O(n^2)的算法有很多,我这随便贴一个烂的,跑了375ms. #include<iostream> #include<algorithm> using namespa ...

  7. POJ 2352 树状数组

    学习自:链接以及百度百科 以及:https://www.bilibili.com/video/av18735440?from=search&seid=363548948825132979 理解 ...

  8. POJ 2299树状数组求逆序对

    求逆序对最常用的方法就是树状数组了,确实,树状数组是非常优秀的一种算法.在做POJ2299时,接触到了这个算法,理解起来还是有一定难度的,那么下面我就总结一下思路: 首先:因为题目中a[i]可以到99 ...

  9. MooFest POJ - 1990 (树状数组)

    Every year, Farmer John's N (1 <= N <= 20,000) cows attend "MooFest",a social gather ...

随机推荐

  1. 基于SpringMVC下的Rest服务框架搭建【集成Swagger】

    1.需求背景 SpringMVC本身就可以开发出基于rest风格的服务,通过简单的配置,即可快速开发出一个可供客户端调用的rest服务,通常这些服务要不就是用于手机app的开发,要不就是提供给第三方开 ...

  2. HBase体系结构(转)

    HBase的服务器体系结构遵循简单的主从服务器架构,它由HRegion服务器(HRegion Server)群和HBase Master服务器(HBase Master Server)构成.HBase ...

  3. [转载]iOS 归档操作 NSCoding

    最近一个项目需要保存到本地文件,想用plist,但是发现很多内容是自定义的,于是只能自己归档接档.不难,找了一篇范文大家保存一下,方便以后学习使用. 转自:http://mobile.51cto.co ...

  4. 通过 Code First 开发建立新数据库

    必备条件 要完成本演练,需要安装 Visual Studio 2010 或 Visual Studio 2012. 如果使用的是 Visual Studio 2010,还需要安装 NuGet. 1.创 ...

  5. bootstrap-进度条

    <div class="container"> <div class="row"> <div class="col-lg ...

  6. sublime plugin emmet toolkit

    [简写规则]1. E 代表HTML标签.2. E#id 代表id属性.3. E.class 代表class属性.4. E[attr=foo] 代表某一个特定属性.5. E{foo} 代表标签包含的内容 ...

  7. EBS密码安全的几个参数

    PROFILE Name 1.Signon Password Failure Limit 输入错误次数限制,一旦被锁定需要系统管理员重置解锁 除了后台表系统中没有的地方可以体现被锁定的现象 此功能使用 ...

  8. python-appium识别元素等待时间

    1.显式等待 一个显式等待是你定义的一段代码,用于等待某个条件发生然后再继续执行后续代码. from selenium import webdriverfrom selenium.webdriver. ...

  9. .net实现调用本地exe等应用程序的办法总结

    根据客户需求用户要实现在一个BS系统上打开本地的一应用程序,在网上查了好多资料再加上自己的各种测试,到最后功能是实现了,只不过还存在一些问题,接下来会先把各种方法一一列举出来 1.先写最终测试通过的这 ...

  10. Inside The C++ Object Model - 03

    object Lessons 1.C++中布局以及存取时间上的的额外负担是由virtual引起的:virtual function.virtual base class.或是由于多继承引起的. 2.C ...