http://acm.hdu.edu.cn/showproblem.php?pid=4325
Problem Descriptionas is known to all, the blooming time and duration varies between different kinds of flowers. Now there are a garden planted full of flowers. The gardener wants to know how many flowers would bloom in the garden in a specific time. But there is too many flowers in the garden, so he wants your to help him.
Inputthe first line contains a single integer t (1 <= t <=), the number of test cases.
For each case, the first line contains both integer N and M, where N (1 <= n <= 10^5) is the number of the flowers, and M (1 <= M <= 10^5) is the query times.
In the next N lines, each line contains the integer Si and ti (1 <= si <= Ti <= 10^9), means i-th flower would be Blooming at time [Si, Ti].
The next M lines, each line contains an integer Ti, means the time of i-th query.
Outputfor each case, output the case number as shown and then print M lines. Each line contains an integer, meaning the number of blooming flowers.
Sample outputs is available for more details.
Sample Input
21 15 1042 31 44 8146
Sample Output
Case #1:0Case #2:121
/**hdu 4325 Tree Array + discretization topic: given n flowers, each flower open time period, and then M asked: Ti time point How many flowers are blooming problem-solving ideas: tree-like array naked, but to disperse the bloom time */#include <stdio.h># Include <string.h> #include <iostream> #include <algorithm>using namespace std;const int maxn=300005; int n,m,k;int c[maxn],a[maxn];struct note{int x,id; BOOL Operator < (const note &other) const {return x<other.x; }}p[maxn];int lowbit (int i) {return i& (-i);} int sum (int x) {int cnt=0; while (x>0) {cnt+=c[x]; X-=lowbit (x); } return CNT;} void Update (int pos,int value) {while (pos<=k) {c[pos]+=value; Pos+=lowbit (POS); }}int Main () {int t,tt=0; scanf ("%d", &t); while (t--) {scanf ("%d%d", &n,&m); int nn=n*2; int mm=nn+m; for (int i=0;i<mm;i++) {scanf ("%d", &p[i].x); P[i].id=i; } sort (p,p+mm); I=s; A[p[0].id]=k; for (int i=1;i<mm;i++) {if (p[i].x==p[i-1].x) {a[p[i].id]=k; } else a[p[i].id]=++k; } memset (C,0,sizeof (C)); for (int i=0;i<nn-1;i+=2) {update (a[i],1); Update (A[I+1]+1,-1); } printf ("Case #%d:\n", ++TT); for (int i=nn;i<mm;i++) {printf ("%d\n", SUM (A[i])); }} return 0;}
hdu4325 tree-like array + discretization