Created
November 18, 2014 15:47
-
-
Save SilverRainZ/86ca2a636912c7ce988a to your computer and use it in GitHub Desktop.
Stars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstring> | |
#include <algorithm> | |
#include <cmath> | |
#define z0(x) memset(x, 0, sizeof(x)) | |
#define z1(x) memset(x, -1, sizeof(x)) | |
#define N 150010 | |
using namespace std; | |
typedef struct star{ | |
int x, y; | |
}star; | |
int c[N]; | |
int ans[N]; | |
star stars[N]; | |
int n; | |
int lowbit(int x) | |
{ | |
return x&(-x); | |
} | |
int sum(int n) | |
{ | |
int sum = 0; | |
while (n > 0){ | |
sum += c[n]; | |
n -= lowbit(n); //? | |
} | |
return sum; | |
} | |
void updata(int i, int num) | |
{ | |
while (i <= n){ | |
c[i] += num; | |
i += lowbit(i); | |
} | |
} | |
int main() | |
{ | |
z0(stars); z0(c); z0(ans); | |
scanf("%d",&n); | |
for (int i = 0; i < n; i++){ | |
scanf("%d%d",&stars[i].x, &stars[i].y); | |
stars[i].x++; | |
} | |
for (int i = 0; i < n; i++){ | |
ans[sum(stars[i].x)]++; | |
updata(stars[i].x,1); | |
} | |
for (int i = 0; i < n; i++){ | |
printf("%d\n",ans[i]); | |
} | |
system("pause."); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment