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

n行 {

}。

$$\sum^{n}_{j = 1}=1(x_j<=x_i \&\& y_j<=y_i \&\&i !=j)$$

(sigma 在诸位 dalao 的教下终于打好了)

[![样例](http://poj.org/images/2352_1.jpg " 样例")](http://poj.org/images/2352_1.jpg " 样例")

0 级星集 {1}
1 级星集 {2， 4}
2 级星集 {3}
3 级星集 {5}
4 级星集 ?

（每输入一颗星， 统计横坐标小于该星的数量， 并将这个星的横坐标的位置加 1）

//树状数组
#include <cstdio>
#include <algorithm>
using namespace std;
int n, x, y;
int c[32009], lv[32009];
int lowbit(int x) {
return x & (-x);
}
void add(int x) {
for ( ; x <= 32009; x += lowbit(x))
c[x]++;
}

int sum(int x) {
int z = 0;
for ( ; x > 0; x -= lowbit(x)) {
z += c[x];
}
return z;
}

int main() {
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
int a = sum(x+1);
lv[a]++;
}
for (int i = 0; i < n;i++)
printf("%d\n", lv[i]);
return 0;
}


（我果然菜的抠脚 QAQ）

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cstdio>
using namespace std;

int siz[400004], w[400004], s[4000004][2], tot, pos[400004], fa[400004], root;
int ans[400004];

//int st[40004] = {0, 2, 2, 5, 1};

void up(int i) {
siz[i] = siz[s[i][0]] + siz[s[i][1]] + 1;

return ;
}

void spin(int i, bool lr) {
if (root == i) root = s[i][lr];
bool lr2 = (s[fa[i]][1] == i);

if (fa[i]) {
s[fa[i]][lr2] = s[i][lr];
}
fa[s[i][lr]] = fa[i];

int tmp = s[s[i][lr]][!lr];
s[s[i][lr]][!lr] = i;
fa[i] = s[i][lr];

if (tmp) {
s[i][lr] = tmp;
fa[tmp] = i;
up(i);
up(fa[i]);
return ;
}
s[i][lr] = 0;
up(i);
up(fa[i]);

return ;
}
//需要注意一下相同坐标的插入位置
void ins(int x, int &i) {
if (!i) {
i = ++tot;
siz[i] = 1;
w[i] = x;
pos[i] = rand() % 30000;
return ;
}
siz[i]++;
if (x >= w[i]) {
ins(x, s[i][1]);
fa[s[i][1]] = i;
if (pos[s[i][1]] < pos[i]) {
spin(i, 1);
}

} else if (x < w[i]) {
ins(x, s[i][0]);
fa[s[i][0]] = i;
if (pos[s[i][0]] < pos[i]) {
spin(i, 0);
}
}
return ;
}

int find(int x, int i) {
if (siz[i] == 0) {
return 0;
}
if (x >= w[i]) {
return siz[s[i][0]] + 1 + find(x, s[i][1]);
}
if (x < w[i]) {
return find(x, s[i][0]);
}
}

int main() {
srand(1111111);
//就是这里！用时间种子必 RE。
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
int x, y;
scanf("%d%d", &x, &y);
ins(x, root);//插入坐标
int lvl = find(x, root);//查询排名
ans[lvl]++;
}
for (int i = 1; i <= n; ++i) {
printf("%d\n", ans[i]);
}
return 0;
}


……其实也没什么好加注释的，就介样吧。（ε=ε=ε=┏(゜^゜;)┛逃）

### 6 条评论

#### Sys_Con · 2018年1月11日 10:32 上午

https://sysconkonn.github.io/LaTeX.pdf

#### Sys_Con · 2018年1月10日 6:54 下午

[某个并没有什么用的 LaTeX 教程]http://dralpha.altervista.org/zh/tech/lnotes.pdf

并上不去啊

膜 Master 神威

QAQ
什么是 LATEX

#### konnyakuxzy · 2018年1月11日 1:14 下午

LATEX 的话您可以看看 boshi 大佬写的：
http://k-xzy.cf/archives/1346
基础の那些操作都有讲到，还是很吼滴 QvQ