专栏首页mlpoj------2352 Stars(树状数组)

poj------2352 Stars(树状数组)

Stars

Time Limit: 1000MS

Memory Limit: 65536K

Total Submissions: 30268

Accepted: 13202

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

代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define maxn 32005
 4 #define lowbit(x) ((x)&(-x))
 5 int aa[maxn];
 6 int bb[15005];
 7  void ope(int x)
 8 {
 9     while(x<maxn)
10     {
11      aa[x]++;
12      x+=lowbit(x);
13     }
14 }
15 int getsum(int x)
16 {
17     int ans=0;
18     while(x>0)
19     {
20         ans+=aa[x];
21         x-=lowbit(x);
22     }
23     return ans;
24 }
25 int main()
26 {
27     int nn,i,a;
28     while(scanf("%d",&nn)!=EOF)
29     {
30         memset(aa,0,sizeof(aa));
31         memset(bb,0,sizeof(int)*(nn));
32         for(i=0;i<nn;i++)
33         {
34             scanf("%d%*d",&a);
35             a++;
36             bb[getsum(a)]++;
37             ope(a);
38         }
39          for(i=0;i<nn;i++)
40              printf("%d\n",bb[i]);
41     }
42     return 0;
43 }

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • HDUOJ-----1541 Stars

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

    Gxjun
  • hduoj-----(1068)Girls and Boys(二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/3...

    Gxjun
  • hdu 2473 Junk-Mail Filter (并查集之点的删除)

    Junk-Mail Filter Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 32768/...

    Gxjun
  • POJ2409 Let it Bead(Polya定理)

    "Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As...

    attack
  • HDUOJ-----1541 Stars

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

    Gxjun
  • P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently....

    attack
  • HDU 3032 Nim or not Nim?(Multi-Nim)

    Problem Description Nim is a two-player mathematic game of strategy in which ...

    attack
  • 【Codeforces】1213B - Bad Prices

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 ...

    喜欢ctrl的cxk
  • 使用 PInvoke.net Visual Studio Extension 辅助编写 Win32 函数签名

    2018-07-21 14:35

    walterlv
  • codeforces 1066B(贪心)

    Vova’s house is an array consisting of n elements (yeah, this is the first probl...

    dejavu1zz

扫码关注云+社区

领取腾讯云代金券