标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325
题意:有n种花,每种花都有自己的开花时间段从S到E,有m个查询,每个查询都是一个时间点,求这一时刻有几种花在开花;
#include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<vector> using namespace std; #define N 1001100 #define INF 0x3f3f3f3f #define met(a) memset(a, 0, sizeof(a)) struct node { int x,y; }a[N]; int b[N], f[N]; int main() { int T, n, m, x, t=1, Max; scanf("%d", &T); while(T--) { scanf("%d%d", &n, &m); met(a);met(b);met(f); int k=0; Max = -INF; for(int i=1; i<=n; i++) { scanf("%d %d", &a[i].x, &a[i].y); b[k++]=a[i].x; b[k++]=a[i].x-1; b[k++]=a[i].y; b[k++]=a[i].y+1; } sort(b, b+k); k=unique(b, b+k)-b; for(int i=1; i<=n; i++) { int p=lower_bound(b, b+k, a[i].x)-b; int q=lower_bound(b, b+k, a[i].y)-b; f[p]++; f[q+1]--; Max = max(Max, q+1); } for(int i=1; i<=Max; i++)///防止TLE; f[i] += f[i-1]; printf("Case #%d:\n", t++); while(m--) { scanf("%d", &x); int ans=0; int p=lower_bound(b, b+k, x)-b; ans = f[p]; printf("%d\n", ans); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/zhengguiping--9876/p/4967114.html