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

  1. 5
  2. 1 1
  3. 5 1
  4. 7 1
  5. 3 3
  6. 5 5

Sample Output

  1. 1
  2. 2
  3. 1
  4. 1
  5. 0

Hint

This problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed.
 
星星有坐标,设一颗星星的左边为(a,b),那么他的level就是满足x<a&&y<b的星星个数,用树状数组,树状数组从下标1开始,所以输入x坐标应该加1。
 
代码:
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4. int n,x,y;
  5. int tree[],level[];
  6. int lowbit(int t)
  7. {
  8. return t&-t;
  9. }
  10. void update(int x,int y)
  11. {
  12. for(int i = x;i <= ;i += lowbit(i))
  13. {
  14. tree[i] += y;
  15. }
  16. }
  17. int gettree(int x)
  18. {
  19. int ans = ;
  20. for(int i = x;i > ;i -= lowbit(i))
  21. {
  22. ans += tree[i];
  23. }
  24. return ans;
  25. }
  26. int main()
  27. {
  28. scanf("%d",&n);
  29. for(int i = ;i < n;i ++)
  30. {
  31. scanf("%d%d",&x,&y);
  32. x ++;
  33. level[gettree(x)] ++;
  34. update(x,);
  35. }
  36. for(int i = ;i < n;i ++)
  37. {
  38. printf("%d\n",level[i]);
  39. }
  40. }

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

  10. Stars(树状数组或线段树)

    Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description A ...

随机推荐

  1. springboot与redis的无缝整合(分布式)

    参考博客 : https://blog.csdn.net/csao204282/article/details/54092997 1 首先得引入依赖 <dependency> <gr ...

  2. LVS管理工具--ipvsadm

    一. ipvsadm工具介绍 从2.4版本开始,linux内核默认支持LVS.要使用LVS的能力,只需安装一个LVS的管理工具:ipvsadm. LVS的结构主要分为两部分: 工作在内核空间的IPVS ...

  3. [CTSC2011]幸福路径

    题目描述 有向图 G有n个顶点 1, 2, …, n,点i 的权值为 w(i).现在有一只蚂蚁,从 给定的起点 v0出发,沿着图 G 的边爬行.开始时,它的体力为 1.每爬过一条 边,它的体力都会下降 ...

  4. 20145222黄亚奇《网络对抗》MSF基础应用

    实践目标 掌握metasploit的基本应用方式. 具体需要完成(1)ms08_067;(2)ms11_050:(3)Adobe(4)成功应用任何一个辅助模块. 实验内容 掌握metasploit的基 ...

  5. Qt debug和release

    debug会默认给变量赋初始值,但是release不会. 所以: 在头文件中声明指针P* p时,最好给它初始化:P* p=NULL; 不然有可能造成野指针的情况

  6. MarkDown初学者使用指南

    换MarkDown编辑器了,突然发现自己不会,尴尬!所以顺便总结下Markdown的常用语法 标题 一级标题(格式:#+XXXXX) 二级标题(格式:##+XXXXXX) 三级标题(格式:###+XX ...

  7. SpringBoot MockMVC

    使用MockMvc,我们可以完成基于RESTful风格的SpringMVC的测试,我们可以测试完整的Spring MVC流程,即从URL请求到控制器处理,再到视图渲染都可以测试. @RunWith(S ...

  8. 2 Powershell与Cmd以及Unix/Linux Shell

    上篇文章我说道,windows为了改变用户对其console界面的诟病,于是就从windows   vista开始,计划要改变这种局面,于是就有 了Powershell的出现. 1.兼容shell命令 ...

  9. hive 数据清理--数据去重

    hive> select * from (select *,row_number() over (partition by id) num from t_link) t where t.num= ...

  10. 在线演示demo

    *{display:none} 仿微博添加和删除动画 body{} input,button,select,textarea{outline:none;} .sdiv{width:400px;} .b ...