Stars

Time limit: 0.25 second
Memory limit: 64 MB
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 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 ofY 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 output
5
1 1
5 1
7 1
3 3
5 5
1
2
1
1
0

分析:树状数组;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,a[maxn],ans[maxn];
int get(int x)
{
int sum=;
for(int i=x;i;i-=i&(-i))
sum+=a[i];
return sum;
}
void add(int x,int y)
{
for(int i=x;i<=;i+=i&(-i))
a[i]+=y;
}
int main()
{
int i,j;
scanf("%d",&n);
rep(i,,n)
{
int x,y;
scanf("%d%d",&x,&y);
x++;
ans[get(x)]++;
add(x,);
}
rep(i,,n-)printf("%d\n",ans[i]);
//system("Pause");
return ;
}

ural1028 Stars的更多相关文章

  1. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

  2. POJ 2352 Stars(树状数组)

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

  3. 【POJ-2482】Stars in your window 线段树 + 扫描线

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted:  ...

  4. Java基础之在窗口中绘图——填充星型(StarApplet 2 filled stars)

    Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.GeneralPath; @SuppressWarnin ...

  5. XidianOJ 1177 Counting Stars

    题目描述 "But baby, I've been, I've been praying hard,     Said, no more counting dollars     We'll ...

  6. POJ-2352 Stars 树状数组

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

  7. hdu 1541/poj 2352:Stars(树状数组,经典题)

    Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  8. POJ 2482 Stars in Your Window 线段树扫描线

    Stars in Your Window   Description Fleeting time does not blur my memory of you. Can it really be 4 ...

  9. 2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me

    Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

随机推荐

  1. nopcommerce插件相关

    注意Description.txt中,以下字段必须配置当前可用.我抄人家代码的时候,人家是3.4   我也配成3.4,结果我的nop是3.7的,后台半天显示不出来插件,浪费了一下午.

  2. csdn的调查问卷,好多都不懂哈

    http://bss.csdn.net/cview/reg/?project_id=2412&identy_id=1538

  3. php中header函数参数的 Cache-control:private,no-cache,must-revalidate,max-age 使用方法

    网页的缓存是由HTTP消息头中的“Cache-control”来控制的,常见的取值有private.no-cache.max-age.must-revalidate等,默认为private.其作用根据 ...

  4. MySQL出现Errcode:28错误提示解决办法

    mysql出现Error writing file \'xxx\'( Errcode:28)的原因有很多种,下面我来总结一些常用的关于引起Errcode:28错误原因与解决方法.   问题一,是log ...

  5. zf-关于评价器的开关所在的配置文件,与代码如何修改。

    web.xml文件  把true改成false就是关

  6. windows ORA-12560: TNS: 协议适配器错误

    1.first it report ORA-12560: TNS: 协议适配器错误 手工设定环境变量如下: set ORACLE_HOME=d:\app\OAadmin\product\11.2.0\ ...

  7. HDU1114--Piggy-Bank(完全背包变形)

    Piggy-Bank   Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  8. Lucene add、updateDocument添加、更新与search查询(转)

    package com.lucene;   import java.io.IOException;   import org.apache.lucene.analysis.standard.Stand ...

  9. Linux学习 -- 权限管理

    1 ACL权限 1.1 简介与开启 1.1.1 ACL权限是什么 access control list 访问控制表 解决传统的(owner,group,others)身份不足的情况 可以设置 特定用 ...

  10. Lightoj 1004 - Monkey Banana Problem

    题目链接:http://acm.hust.edu.cn/vjudge/contest/121396#problem/F http://lightoj.com/volume_showproblem.ph ...