标签:style blog io color ar os sp for div
2 3 4 1 3 1 2 2 3 0 1 2 3 1 3 0 0 -1 0 1
0 2 3 2 0 1 0
/*树状数组应用,统计数字在所给区间出现的次数。 TLE哭了,MAX大小:200002是AC,200005是TLE!!! 注意将负数转换到正值区间上,否则还是会TLE!!! */ #include<stdio.h> #include<string.h> #define MAX 200002 int a[MAX]; int lowbit(int N) { return N&(-N); } void asd(int i,int M) { while(i<=MAX) { a[i]+=M; i+=lowbit(i); } } int sum(int j) { int sum=0; while(j>0) { sum+=a[j]; j-=lowbit(j); } return sum; } int main() { int i,n,m,T,t,k,p; scanf("%d",&T); while(T--) { memset(a,0,sizeof(a)); scanf("%d%d",&m,&n); while(m--) { scanf("%d%d",&k,&t); asd(k+100001,1); asd(t+100002,-1); } while(n--) { scanf("%d",&p); printf("%d\n",sum(p+100001)); } } return 0; }
标签:style blog io color ar os sp for div
原文地址:http://blog.csdn.net/hdd871532887/article/details/41220747