Topic Links:
http://poj.org/problem?id=2352
Test instructions:
There are n stars in the coordinates, if a star coordinates (x, y ), its lower-left position is: (x0,y0), X0<=x and Y0<=y. If there is a star at the lower left, it means that the star belongs to level X, the
is incremented by y, and if y is the same, x increments the order of N stars, and the number of levels is calculated.
:
Because y is given in ascending order, the sum of the number of occurrences in the x-coordinate is the sum of the stars in the lower-left position of the second star.
Code:
#include <iostream> #include <algorithm> #include <stdio.h> #include <
String.h> #define MAXN (15005) using namespace std;
int n,m,num[32005],vis[15005];
int lowbit (int x) {return x& (-X);} void Add (int x) {for (int i=x;i<=32001;i+=lowbit (i)) num[i]+=1;
return;
} int query (int x) {int ans=0;
for (int i=x;i>0;i-=lowbit (i)) ans+=num[i];
return ans;
} int main () {scanf ("%d", &n);
for (int i=1;i<=n;i++) {int x, y;
scanf ("%d%d", &x,&y);
x + +;
Add (x);
Vis[query (x)]++;
Cout<<query (x) << "<<vis[query (x)]<<endl;
} for (int i=1;i<=n;i++) printf ("%d\n", Vis[i]); }