poj 2352 Stars (樹狀數組)

來源:互聯網
上載者:User

標籤:

Stars
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 37108   Accepted: 16173

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

51 15 17 13 35 5

Sample Output

12110

Hint

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

Source

Ural Collegiate Programming Contest 1999

依然想不通,智商是硬傷,絕望的想哭,真的想哭。

 

更新於2015年08月04日01:47:18:

好像有點明白了.....詳情看注釋

/*************************************************************************    > File Name: code/poj/2352.cpp    > Author: 111qqz    > Email: [email protected]     > Created Time: 2015年08月04日 星期二 00時33分52秒 ************************************************************************/#include<iostream>#include<iomanip>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<string>#include<map>#include<set>#include<queue>#include<vector>#include<stack>#define y0 abc111qqz#define y1 hust111qqz#define yn hez111qqz#define j1 cute111qqz#define tm crazy111qqz#define lr dying111qqzusing namespace std;#define REP(i, n) for (int i=0;i<int(n);++i)  typedef long long LL;typedef unsigned long long ULL;const int inf = 0x7fffffff;const int N=4E4+7;int a[N];int t[N];int x,y;int n;int lowbit (int x){    return x&(-x);}void update(int x,int c){    int i;    for ( int i = x ; i <= 32001 ; i = i + lowbit(i))    {    t[i] = t[i] + c;    }}int sum( int x){    int i;    int res = 0;    for ( int i = x ; i >= 1 ; i = i-lowbit(i))    {    res = res + t[i];    }  //  cout<<"x:"<<x<<" res:"<<res<<endl;    return res;}int main(){    scanf("%d",&n);    for ( int i = 0 ; i < n ; i ++ )    {    scanf("%d %d",&x,&y);    a[sum(++x)]++;  // ++x是因為座標是從0 開始,而樹狀數組的下標一定是從1開始,不然會TLE            // sum(++x)是求 ++x 的level            //            //    update(x,1);   //向上更新,對於每一個比x大的位置,由於x的存在,那些位置的點的level都會增加1                   //比如對於星3,因為星1的讀入,我向上更新了星2,星3,星4,星5,這時候他們的level都是1               //之後讀入星2,更新了星3和星5,星3的level是2,星5的level也是2,之後由於星4,星5的level又加1,為5.    }    for ( int i = 0 ; i < n ; i ++ )    {    printf("%d\n",a[i]); //數組a存的是level 為i的點有多少個,即為題目所求。    }    return 0;}

 

poj 2352 Stars (樹狀數組)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.