标签:des style blog io ar color os sp for
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10150 Accepted Submission(s): 5161
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define maxn 100001 int d[maxn]; int N,a,b; int lowbit(int x)//求某点的管辖范围 { return x&(-x); } void update(int x,int num)//区间修改 使得a[1]一直修改到a[x] { while(x>0) { d[x]+=num; x-=lowbit(x); } } int getSum(int x)//单点查询 { int s=0; while(x<=N) { s+=d[x]; x+=lowbit(x); } return s; } int main() { while(scanf("%d",&N)!=EOF) { if(N==0) break; memset(d,0,sizeof(d)); for(int i=0;i<N;i++) { scanf("%d%d",&a,&b); update(a-1,-1); update(b,1); } int first=1; for(int i=1;i<=N;i++) { if(first==1) { printf("%d",getSum(i)); first=0; } else { printf(" %d",getSum(i)); } } printf("\n"); } return 0; }
标签:des style blog io ar color os sp for
原文地址:http://www.cnblogs.com/qscqesze/p/4145355.html