poj上1A, HDU上6A,我晕啊!注意几点:
1、多组数据;
2、memset(c, 0, siezeof(c));
3、memset(ans, 0, sizeof(ans));
my code:
View Code
#include <stdio.h>
#include <string.h>
#define N 32010
int c[N], n, ans[N];
int lowbit(int i)
{
return i&(-i);
}
void add(int i, int val)
{
while(i <= N)
{
c[i] += val;
i += lowbit(i);
}
}
int sum(int i)
{
int s = 0;
while(i > 0)
{
s += c[i];
i -= lowbit(i);
}
return s;
}
int main()
{
int i, x, y;
//freopen("data.in", "r", stdin);
while(~scanf("%d", &n))
{
memset(ans, 0, sizeof(ans));
memset(c, 0, sizeof(c));
for(i = 0; i < n; i++)
{
scanf("%d%d", &x, &y);
ans[sum(x+1)]++;
add(x+1, 1);
}
for(i = 0; i < n; i++)
printf("%d\n", ans[i]);
}
return 0;
}