题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 32297 Accepted Submission(s): 15618
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; const LL mod=1e9+7; const LL INF=1e9+7; const int maxn=100000+50; int c[maxn]; int N; int lowbit(int x) { return x&(-x); } void Update(int x,int add) { while(x>0) { c[x]+=add; x-=lowbit(x); } } int sum(int x) { int ret=0; while(x<=N) { ret+=c[x]; x+=lowbit(x); } return ret; } int main() { while(scanf("%d",&N)!=EOF) { if(N==0) break; memset(c,0,sizeof(c)); int M=N; while(M--) { int a,b; scanf("%d%d",&a,&b); Update(b,1); Update(a-1,-1); } printf("%d",sum(1)); for(int i=2;i<=N;i++) printf(" %d",sum(i)); printf("\n"); } return 0; }
原文:https://www.cnblogs.com/caijiaming/p/10885880.html