还是树状数组,只不过这题范围大一点。
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;
typedef long long LL;
const int N = 100010;
const int INF = 1e8;
int tree[N];
int level[N];
int lowbit(int x)
{
return (x & -x);
}
void add(int x, int val)
{
while(x < N)
{
tree[x] += val;
x += lowbit(x);
}
}
int sum(int x)
{
int rankk = 0;
while(x > 0)
{
rankk += tree[x];
x -= lowbit(x);
}
return rankk;
}
int main()
{
// freopen("in.txt", "r", stdin);
int x, y, n;
while(~scanf("%d", &n) && n)
{
memset(tree, 0, sizeof(tree));
for(int i = 1; i <= n; i ++)
{
scanf("%d%d", &x, &y);
add(x, 1);
add(y + 1, -1);
}
for(int i = 1; i < n; i ++)
{
printf("%d ", sum(i));
}
printf("%d\n", sum(n));
}
return 0;
}