描述

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.

输入

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.

输出

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.

样例输入

5
1 1
5 1
7 1
3 3
5 5

样例输出

1
2
1
1
0

提示

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

题目来源

Ural Collegiate 1999

做这题的时候一直超时。后来借了贞贞的代码看了,cjx更加混乱了,就两处地方改一改就不超时了。

实在搞不懂,求大神解答!

#include <stdio.h>
#include <string.h>
#define MAXN 32110 int n,m;
int L[];
int C[MAXN];
int lowbit(int t){
return t&(t^(t-));
}
int sum(int end){
int sum();
while(end>){
sum+=C[end];
end-=lowbit(end);
}
return sum;
} void add(int pos, int num){
while(pos<=MAXN){
C[pos]+=num;
pos+=lowbit(pos);
}
} int main(int argc, char *argv[])
{
int x,y;
scanf("%d",&n);
for(int i=; i<=n; i++){
scanf("%d%d",&x,&y);
x++;
add(x,);
L[sum(x)]++;
//----超时代码---
int level=sum(x);
L[level]++;
add(x,);
//---------------
}
for(int i=; i<=n; i++)
printf("%d\n",L[i]);
//----超时代码---
for(int i=; i<n; i++)
printf("%d\n",L[i]);
//---------------
return ;
}

TOJ 2711 Stars的更多相关文章

  1. poj 2352 Stars 数星星 详解

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

  2. TOJ 2776 CD Making

    TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性...  贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...

  3. POJ 2352 Stars(树状数组)

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

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

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

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

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

  6. XidianOJ 1177 Counting Stars

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

  7. POJ-2352 Stars 树状数组

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

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

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

  9. 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 ...

随机推荐

  1. SQL server 查询语句优先级-摘抄

    SQL 不同于与其他编程语言的最明显特征是处理代码的顺序.在大数编程语言中,代码按编码顺序被处理,但是在SQL语言中,第一个被处理的子句是FROM子句,尽管SELECT语句第一个出现,但是几乎总是最后 ...

  2. DISCUZ 各数据库表作用

    链接原文:http://forum.digitser.cn/forum.php?mod=viewthread&tid=179 DISCUZ数据字典               http://w ...

  3. LOSKI,我

    2019年入驻github以及博客园 在发现用github的issue写博客稍微有些奇怪后决定开辟这个更适合写博的空间 2019/4/1 目前大一,计算机专业,尚未分流 更多的时间花在了数据结构与算法 ...

  4. postgreSQL PL/SQL编程学习笔记(一)

    1.Structure of PL/pgSQL The structure of PL/pgSQL is like below: [ <<label>> ] [ DECLARE ...

  5. 3、pandas

    原文出处: pandas.pydata.org   译文出处:石卓林 这是关于pandas的简短介绍,主要面向新用户.可以参阅Cookbook了解更复杂的使用方法. 链接:http://python. ...

  6. Exadata 18.1新特性--计算节点升级增强

    新的计算节点升级增强能大幅缩短升级花费的时间,最快能减少40%的时间,具体的增强主要体现在以下方面: 1.计算节点操作系统的备份工作. 以前计算节点操作系统的备份工作是在正式升级之前执行,在滚动升级过 ...

  7. A printf format reference page (cheat sheet)

    Summary: This page is a printf formatting cheat sheet. I originally created this cheat sheet for my ...

  8. EasyUI学习笔记(三)—— message和menubutton的使用

    一.message(消息框) 1.1 alert   <script type="text/javascript"> $(function () { // alert方 ...

  9. clustalX2使用以及相关的问题

    Clustalx的操作 第一步:输入序列文件. 第二步:设定比对的一些参数. 参数设定窗口. 第三步:开始序列比对. 第四步:比对完成,选择保存结果文件的格式 相关问题 CLUSTALX-是CLUST ...

  10. BT网站--Python开发爬虫代替.NET

    BT网站-奥修磁力-Python开发爬虫代替.NET写的爬虫,主要演示访问速度和在一千万左右的HASH记录中索引效率. IBMID 磁力下载- WWW.IBMID.COM  现在用的是Python + ...