Stars

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 58255   Accepted: 24860

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

 
话不多说,都在代码里了..
/*
读题很容易知道,每一颗star i 只需要那些满足 j.time < i.time and j.row <= i.row的star即可,依题意我们知道这刚好就是输入顺序。
so 我们只需要选择那些在某个star之前放的并且row小于等于他的star。
所以我们可以把i.row插入,即可查出在某个数j插入之前row.i < row.j的数量
*/
#include <cstdio>
using namespace std; const int maxn = 32000 + 5;
int n, c[maxn], ans[maxn]; int lowbit(int x) {
return x & (-x);
} void add(int x, int d) {
while(x <= maxn) {
c[x] += d;
x += lowbit(x);
}
} int query(int x) {
int sum = 0;
while(x > 0) {
sum += c[x];
x -= lowbit(x);
}
return sum;
} int main() {
int x, y;
scanf("%d", &n);
for(int i = 0; i < n; i ++) {
scanf("%d %d", &x, &y);
x += 1;
ans[query(x)] ++;
add(x, 1);
}
for(int i = 0; i < n; i ++) {
printf("%d\n", ans[i]);
}
return 0;
}
 
 

POJ-2352.Stats(树状数组简单应用)的更多相关文章

  1. POJ 2352 【树状数组】

    题意: 给了很多星星的坐标,星星的特征值是不比他自己本身高而且不在它右边的星星数. 给定的输入数据是按照y升序排序的,y相同的情况下按照x排列,x和y都是介于0和32000之间的整数.每个坐标最多有一 ...

  2. poj 2229 Ultra-QuickSort(树状数组求逆序数)

    题目链接:http://poj.org/problem?id=2299 题目大意:给定n个数,要求这些数构成的逆序对的个数. 可以采用归并排序,也可以使用树状数组 可以把数一个个插入到树状数组中, 每 ...

  3. POJ 2299 【树状数组 离散化】

    题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...

  4. poj 2155 Matrix (树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16797   Accepted: 6312 Descripti ...

  5. POJ 2155 Matrix[树状数组+差分]

    原题链接:https://vjudge.net/problem/POJ-2155 题目大意 给定 n* n 矩阵A,其元素为0或1. A [i][j] 表示第i行和第j列中的数字.最初全为0. 我们有 ...

  6. POJ 2155 Matrix (树状数组 && 区间计数)

    题意 : 给出一个N*N的矩阵, 矩阵只有可能包含0或1, 一开始则全部是0.对于矩阵可以进行两种操作, 第一种是输入 C x1 y1 x2 y2 表示, 对以(x1, y1)为左上角, 以(x2, ...

  7. poj 3067 - Japan(树状数组)

    先按第一个数从大到小排序,相等的情况下,第二个数按照从大到小排序..... 预处理后,照着树状数组写就行了... 注意:k的最大值应取1000*1000 代码如下: include <cstdi ...

  8. poj 2481 - Cows(树状数组)

    看的人家的思路,没有理解清楚,,, 结果一直改一直交,,wa了4次才交上,,, 注意: 为了使用树状数组,我们要按照e从大到小排序.但s要从小到大.(我开始的时候错在这里了) 代码如下: #inclu ...

  9. POJ 1990 MooFest --树状数组

    题意:牛的听力为v,两头牛i,j之间交流,需要max(v[i],v[j])*dist(i,j)的音量.求所有两两头牛交谈时音量总和∑(max(v[i],v[j])*abs(x[j]-x[i])) ,x ...

随机推荐

  1. Flutter-使用Dialog時出現No MaterialLocalizations found

    在显示SimpleDialog时候程序报错 No MaterialLocalizations found 没有找到 MaterialLocalizations 搜索找到原因 runApp 需要先调用 ...

  2. expect自动远程拷贝脚本

    expect自动远程拷贝脚本,利用rsync命令,脚本内容如下: #!/usr/bin/expect -- proc Usage_Exit {self} { puts "" put ...

  3. 关于win7虚拟机的安装

    VMware 安装以及秘钥 win7的光盘文件

  4. 运行biggan demo

    http://www.zhuanzhi.ai/document/8705953a704e1bf8e051c161d1587d88

  5. 【leetcode】Reaching Points

    题目如下: A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y). G ...

  6. 链表中倒数第k个节点(python)

    题目描述 输入一个链表,输出该链表中倒数第k个结点. 无力吐槽牛客网... class Solution: def FindKthToTail(self, head, k): # write code ...

  7. Visual Studio2015 community 许可证到期问题

    申请微软账户直接登录可以继续使用.

  8. Parse error: syntax error, unexpected 'class' (T_CLASS)

    电脑坏了重新下载代码. 结果报错 Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_ST ...

  9. xargs -i参数详解

    学习所需,文章转载过来! xargs与find经常结合来进行文件操作,平时删日志的时候只是习惯的去删除,比如 # find . -type f -name "*.log" | xa ...

  10. 【洛谷P5018 对称二叉树】

    话说这图也太大了吧 这题十分的简单,我们可以用两个指针指向左右两个对称的东西,然后比较就行了 复杂度O(n*logn) #include<bits/stdc++.h> using name ...