标签:
#include<stdio.h> #include<stdlib.h> #include<math.h> #include<iostream> #include<string.h> #include<algorithm> #include<vector> using namespace std; #define N 1100000 struct node { int x,y; }a[N]; int f[N],p[N]; int main() { int T,n,m,i,t=1; scanf("%d",&T); while(T--) { memset(p,0,sizeof(p)); memset(a,0,sizeof(a)); memset(f,0,sizeof(f)); int k=0; scanf("%d %d",&n,&m); for(i=0;i<n;i++) { scanf("%d %d",&a[i].x,&a[i].y); p[k++]=a[i].x; p[k++]=a[i].x-1; p[k++]=a[i].y; p[k++]=a[i].y+1; } sort(p,p+k); int len=unique(p,p+k)-p; int Max=0; for(i=0;i<n;i++) { int u=lower_bound(p,p+len,a[i].x)-p; int v=lower_bound(p,p+len,a[i].y)-p; f[u]++; f[v+1]--; Max=max(Max,v+1); } for(i=1;i<=Max;i++)//防止TLE { f[i]+=f[i-1]; } printf("Case #%d:\n",t++); while(m--) { int b; scanf("%d",&b); int u=lower_bound(p,p+len,b)-p; printf("%d\n",f[u]); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/linliu/p/4975461.html