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

┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉

题意:给出一堆星星的坐标,求每个星星左侧和下侧空间内的所有星星数量

思路:因为发现输入里y是递增输入的,所以输入当前这个星星的时候,它前面的所有星星肯定都在它下面(或者和它一行)

就转化为求之前输入的那些星星有多少个x坐标比它小的,用树状数组来维护

树状数组。。还不怎么会用哇。。。

数组大小开的。。emm是一个迷

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
#define SZ 320200
int a[SZ], d[SZ], t[SZ], n;
void add(int i, int x)
{
for(; i <= ; i += (i & -i))
d[i] += x;
}
int get(int i)
{
int ans = ;
for(; i; i -= (i & -i))
ans += d[i];
return ans;
} int main()
{
int n;
scanf("%d", &n);
for(int i = ; i < n; i++)
{
int x, y;
scanf("%d %d", &x, &y);
x++;//x可能等于0,把它们都+1
int ans = get(x);//求x之前的所有的和(前缀和,就是当前点的等级
t[ans]++;
add(x, );
}
for(int i = ; i < n; i++) printf("%d\n", t[i]);
return ;
}

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

  1. [树状数组]数星星 Stars

    数 星 星 S t a r s 数星星 Stars 数星星Stars 题目描述 天空中有一些星星,这些星星都在不同的位置,每个星星有个坐标.如果一个星星的左下方(包含正左和正下)有 k k k 颗星星 ...

  2. 树状数组入门 hdu1541 Stars

    树状数组 树状数组(Binary Indexed Tree(B.I.T), Fenwick Tree)是一个查询和修改复杂度都为log(n)的数据结构.主要用于查询任意两位之间的所有元素之和,但是每次 ...

  3. 线段树/树状数组 POJ 2182 Lost Cows

    题目传送门 题意:n头牛,1~n的id给它们乱序编号,已知每头牛前面有多少头牛的编号是比它小的,求原来乱序的编号 分析:从后往前考虑,最后一头牛a[i] = 0,那么它的编号为第a[i] + 1编号: ...

  4. 树状数组 || POJ 3321 Apple Tree

    一道dfs序+树状数组的题 因为并没有get到dfs序以及对树状数组也不熟练卡了很久orz dfs序: in和out是时间戳 dfs序可以将树转化成为一个序列,满足区间 -> 子树 然后就可以用 ...

  5. LCA+树状数组 POJ 2763 Housewife Wind

    题目传送门 题意:两种操作,问u到v的距离,并且u走到了v:把第i条边距离改成w 分析:根据DFS访问顺序,将树处理成链状的,那么回边处理成负权值,那么LCA加上BIT能够知道u到v的距离,BIT存储 ...

  6. 树状数组 POJ 2481 Cows

    题目传送门 #include <cstdio> #include <cstring> #include <algorithm> using namespace st ...

  7. POJ 2352 Stars(树状数组)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30496   Accepted: 13316 Descripti ...

  8. POJ 2352 &amp;&amp; HDU 1541 Stars (树状数组)

    一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~ ...

  9. 【树状数组】POJ 2352 Stars

    /** * @author johnsondu * @time 2015-8-22 * @type Binary Index Tree * ignore the coordinate of y and ...

随机推荐

  1. html marquee 标签(转)

    该标签不是HTML3.2的一部分,并且只支持MSIE3以后内核,所以如果你使用非IE内核浏览器(如:Netscape)可能无法看到下面一些很有意思的效果该标签是个容器标签语法: <marquee ...

  2. vs2008打开类视图,看不到类的解决方法

    去工程文件中删除ncb文件,重新打开工程

  3. UVaLive 3401 Colored Cubes (暴力)

    题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同. 析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值. 代码如下: #pragma comment(linker, &qu ...

  4. java使用new Date()和System.currentTimeMillis()获取当前时间戳(转载)

    转自:http://www.cnblogs.com/wuchen/archive/2012/06/30/2570746.html 在开发过程中,通常很多人都习惯使用new Date()来获取当前时间, ...

  5. git中文件的三种状态

    用xcode的时候,左侧栏文件的邮右边时不时会看到M,A这一类的字母.当然,这些以后再写上.先说一下git里文件的三种状态 已提交(committed)  已经提交的本地仓库(repository), ...

  6. POJ1236【图的前连通(缩点)】

    题意: 1.初始至少需要向多少个学校发放软件,使得网络内所有的学校最终都能得到软件. 2.至少需要添加几条传输线路(边),使任意向一个学校发放软件后,经过若干次传送,网络内所有的学校最终都能得到软件. ...

  7. combobox级联检索下拉选择框

    1.效果图 2.前端 @{ ViewBag.Title = "Index"; Layout = null; @*自动筛选下拉框*@ <script src="~/S ...

  8. 初识Sklearn-IrisData训练与预测

    笔记:机器学习入门---鸢尾花分类 Sklearn 本身就有很多数据库,可以用来练习. 以 Iris 的数据为例,这种花有四个属性,花瓣的长宽,茎的长宽,根据这些属性把花分为三类:山鸢尾花Setosa ...

  9. [USACO10FEB]购买巧克力Chocolate Buying 【假背包真贪心】 By cellur925

    题目传送门 继续dp刷题计划,看到这道题,第一眼感觉不就是显然的完全背包嘛.把背包打完要开始填充数组大小的时候成为了mengbier,发现数据极大,达到了1e18.显然这不是一道平凡的背包题目. 于是 ...

  10. C#程序结构与基本语法

    C# 程序结构 Hello World 实例 一个 C# 程序主要包括以下部分: 命名空间声明(Namespace declaration) 一个 class Class 方法 Class 属性 一个 ...