Stars
Time Limit: 1000MS |
|
Memory Limit: 65536KB |
|
64bit IO Format: %i64d &%i64u |
Submit Status
Description
Astronomers often examine star maps where stars is represented by points on a plane and each star have Cartesian Coordinat Es. The level of a star is a amount of the stars that is not higher and is not 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 above. Level of the star number 5 are 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 is 1. At this map there is only one star of the level 0, and the level 1, one star of the level 2, and one star of the Level 3.
You is to write a program, that would 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 (both integers X and Y per line separated by a space, 0<=x,y<=320 ). There can be is only one star at a point of the the plane. Stars is listed in ascending order of Y coordinate. Stars with equal Y coordinates is listed in ascending order of X coordinate.
Output
The output should contain N lines, one number per line. The first line contains amount's 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
At first, we thought that the two-dimensional tree array would be used to find the elements in the matrix. But only one-dimensional ... Then the seniors suggested that the Y is incremented, that is, star i+1 must be on the right side of star I, so just determine if it is below. The title then becomes the first n of a one-dimensional tree array and, if star appears, the x-coordinate point is labeled 1. And then there's a pit point where x may be 0, but the tree array starts at 1. Therefore, each point in the topic is moved back 1 units, the answer does not affect
Code:
#include <iostream> #include <algorithm> #include <cstdlib> #include <sstream> #include < cstring> #include <cstdio> #include <string> #include <deque> #include <cmath> #include < queue> #include <set> #include <map>using namespace std;int tree[32010],n;int pos[15010];inline int Lowbit (const int &k) {return k&-k;} inline void Add (int k,const int &val) {while (k<=32009) {tree[k]+=val;k+=lowbit (k);} return;} inline int getsum (int k) {int sum=0;while (k) {sum+=tree[k];k-=lowbit (k);} return sum;} int main (void) {Ios::sync_with_stdio (false); int I,j,val,x,y;while (cin>>n) {memset (pos,0,sizeof (POS)); Memset ( Tree,0,sizeof (tree)); for (i=1; i<=n; i++) {cin>>x>>y;pos[getsum (++x)]++;add (x,1);} for (i=0; i<n; i++) {Cout<<pos[i]<<endl;}} return 0;}
Zhou Sai (POJ3252)--b.stars (tree-like array)