Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 17276 Accepted Submission(s): 8640
当N = 0,输入结束。
/* 每次更新a到b区间就可以了 */ #include<iostream> #include<string.h> #include<stdio.h> #define N 100010 using namespace std; int c[N]; int n,a,b; int lowbit(int x) { return x&(-x); } void update(int x,int val) { while(x<=n) { c[x]+=val; x+=lowbit(x); } } int getsum(int x) { int s=0; while(x>0) { s+=c[x]; x-=lowbit(x); } return s; } int main() { //freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin); while(scanf("%d",&n)!=EOF&&n) { memset(c,0,sizeof c); //cout<<n<<endl; for(int i=0;i<n;i++) { scanf("%d%d",&a,&b); //cout<<a<<" "<<b<<endl; update(a,1);//更新状态 update(b+1,-1);//更新状态 } //cout<<"ok"<<endl; for(int i=1;i<n;i++) { printf("%d ",getsum(i)); //cout<<i<<endl; } printf("%d\n",getsum(n)); } return 0; }