标签:des style blog http color java os io
Time Limit: 3000 MS Memory Limit: 32768 KB
64-bit integer IO format: %I64d , %I64u Java class name: Main
3 1 1 2 2 3 3 3 1 1 1 2 1 3 0
1 1 1 3 2 1
#include <iostream> #include <string.h> #include <stdio.h> using namespace std; #define max 100005 int c[max]; int n; int lowbit(int x) { return x&-x; } void update(int i,int val) { while(i>0) { c[i]+=val; i-=lowbit(i); } } int get_sum(int i) { int s=0; while(i<=n) { s+=c[i]; ///上下两行 不可换位置~~~~~ i+=lowbit(i); } return s; } int main() { while(scanf("%d",&n),n) { int x,y; memset(c,0,sizeof(c)); for(int i=0; i<n; i++) { scanf("%d%d",&x,&y); update(y,1); update(x-1,-1); } for(int i=1; i<n; i++) ///注意脚标 printf("%d ",get_sum(i)); printf("%d\n",get_sum(n)); } return 0; }
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/zhangying/p/3903978.html