描述

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. windows phone 换肤(2)

    //这里有篇参考文章 http://www.cnblogs.com/tianhonghui/p/3373276.html#commentform 以下思路是来自徐老师,昨晚看了一个晚上球赛,睡了不到6 ...

  2. switch case 判断是否为按钮、设置属性 Load Foreach 绑定事件

    private void button9_Click(object sender, EventArgs e) { foreach (Control CT in this.Controls) {//判断 ...

  3. mysql sp 练习游标和预编译

    create procedure Jack_count_cur_dual() BEGIN ); ; DECLARE mycur CURSOR for SELECT table_name FROM tt ...

  4. 「JSOI2009」球队收益 / 球队预算

    题目链接 戳我 \(Solution\) 我们发现这道题目并不好做,因为要考虑两个因素对答案的影响.于是我们假设接下来的\(m\)场比赛双方都输了.这要我们就只要考虑赢一场对答案的影响了,那每赢一场输 ...

  5. oracle为IN OUT变量或OUT变量赋值时提示“表达式''不能用作赋值目标”

    是因为IN OUT变量和OUT变量是要输出的,不能赋给它常量值,这样它就不能再被赋值而输出了,所以是禁止赋常量值的,比如''也是常量值,也不可以赋给这两种类型的变量,如果不能把存储过程中的其他变量赋给 ...

  6. 【bzoj3309】DZY Loves Math 莫比乌斯反演+线性筛

    Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007)=1, f(1)=0. 给定正整数a,b, ...

  7. 洛谷P4009 汽车加油行驶问题(分层最短路)

    传送门 说好的网络流24题呢……上次是状压dp,这次怎么又最短路了…… 不过倒是用这题好好学了一下分层图最短路 把每一个位置$(x,y)$,油量剩余$k$表示为一个状态,然后转化成一个$n$进制数,这 ...

  8. arx创建作用域(于)当前文档全局变量

    普通的全局变量是作用于整个AutoCAD程序中,所有的文档都将能存取,某些时候,我们需要某一个全局变量仅仅在当前文档有效,便于程序之间通信或者变量值记忆. 在高版本的objectARX向导中,已经为我 ...

  9. (转)2-SAT小结

    2-sat小结 原文作者:老K 原文传送门 2-sat是什么 一类问题是这样的: (两个符号的意思 \(\lor \ or,\land \ and\)) 有n个布尔变量,现在对它们做出限制,比如\(a ...

  10. c语言数据结构学习心得——数据结构基本概念

    1.数据>数据元素>数据项      数据的基本单位是数据元素,数据元素的基本单位是数据项 2.运算的定义->针对逻辑结构 集合:同属于一个集合,无其他关系.(数学上的集合) 线性结 ...