2019-01-28[HDU-1541]树状数组
2019-01-28 本文已影响0人
林锦天
include<iostream>
include<cstring>
using namespace std;
int ans[32005];
int c[32005];
void addd(int x)
{
while (x < 32005)
{
c[x]++;
x += x& (-x);
}
}
int sum(int x)
{
int sum = 0;
while (x > 0)
{
sum += c[x];
x -= x & (-x);
}
return sum;
}
int main()
{
long long n,m;
while (cin >> n && n != 0)
{
memset(c, 0, sizeof(c));
memset(ans, 0, sizeof(ans));
m = n;
while (n--)
{
int x, y;
cin >> x >> y; x++;
ans[sum(x)]++;
addd(x);
}
for (int i = 0; i < m; i++)
cout << ans[i] << endl;
}
}