标签:
http://acm.hdu.edu.cn/showproblem.php?pid=4325
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2633 Accepted Submission(s): 1290
#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<algorithm> using namespace std; typedef long long ll; const int N = 2000010; const int INF = 0x3f3f3f3f; int c[2 * N], a[N], b[N], used[N], d[N]; int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int main() { int t, n, m, f = 0; int p, q, k, e; scanf("%d", &t); while(t--) { f++; k = 0; memset(used, 0, sizeof(used)); scanf("%d%d", &n, &m); for(int i = 0 ; i < n ; i++) { scanf("%d%d", &p, &q); a[i] = p; b[i] = q; c[k++] = p; c[k++] = p - 1;/***///这里为嘛,个人认为是防止查询的数比q要小 c[k++] = q; c[k++] = q + 1;/***/ } qsort(c, k, sizeof(c[0]), cmp); k = unique (c, c + k)- c;//去重 int x, y, maxn = -INF; for(int i = 0 ; i < n ; i++) { x = lower_bound(c, c + k, a[i]) - c; y = lower_bound(c, c + k, b[i]) - c; used[x]++; used[y + 1]--; maxn = max(maxn, y + 1); } for(int i = 0 ; i < maxn ; i++) used[i + 1] += used[i]; printf("Case #%d:\n", f); while(m--) { scanf("%d", &e); int s = lower_bound(c, c + k, e) - c; printf("%d\n", used[s]); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/qq2424260747/p/4974699.html