#include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include <queue> #include <vector> #include <cstdio> #define MAXN 100005 int c[MAXN]; int lowbit(int x) { return x&(-x); } void update(int x,int num) { while(x>0) { c[x]+=num; x-=lowbit(x); } } int getSum(int x) { int s=0; while(x<=MAXN) { s+=c[x]; x+=lowbit(x); } return s; } int main() { //freopen("in.txt","r",stdin); int n,a,b; while(~scanf("%d",&n)&&n) { memset(c,0,sizeof(c)); for(int j=1; j<=n; j++) { scanf("%d%d",&a,&b); update(b,1); update(a-1,-1); } for(int i=1; i<n; i++) printf("%d ",getSum(i)); printf("%d\n",getSum(n)); } return 0; }
时间: 2024-10-01 02:21:02