Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11231 Accepted Submission(s): 5595
3 1 1 2 2 3 3 3 1 1 1 2 1 3 0
1 1 1 3 2 1
#include#include #include using namespace std; const int MAX=100005; int a[MAX],c[MAX]; int low(int n){ return n&(-n); } void add(int p,int q,int n){ while(p<=n){ c[p]+=q; p+=low(p); } } int sum(int n){ int result=0; while(n!=0){ result+=c[n]; n-=low(n); } return result; } int main() { int n,m,i,j,a,b; while(scanf("%d",&n),n){ memset(c,0,sizeof(c)); for(i=1;i<=n;++i){ scanf("%d%d",&a,&b); add(a,1,n); add(b+1,-1,n); } printf("%d",sum(1)); for(i=2;i<=n;++i){ printf(" %d",sum(i)); } printf("\n"); } return 0; }