Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4417
Title: give you the number of N, subscript 0 to N-1,m query, ask the query interval [l,r] is less than or equal to the number of x is how many.
It's funny when I write. or write too little.
We query by x from small to large, then find the point on the interval, if it is less or equal, insert it, and see how many points are inserted in the interval.
The points can also be sorted.
See the code:
1#include <cstdio>2#include <cmath>3#include <algorithm>4#include <cstring>5#include <vector>6 using namespacestd;7typedef pair<int,int>PII;8 9 Const intMax_n =100100;Ten intBit[max_n]; One PII A[max_n]; A intAns[max_n]; - structnode{ - intQl,qr,qh,idx; the BOOL operator< (Constnode& a)Const{ - returnqh<A.QH; - } - }; + Node Qq[max_n]; - intt,n,m; + intUB; A at voidAddintIintx) { - while(i<=N) { -Bit[i] + =x; -i+=i&-i; - } - } in - intSuminti) { to intres =0; + while(i>0 ){ -Res + =Bit[i]; theI-= i&-i; * } $ returnRes;Panax Notoginseng } - the + intMain () { Ascanf"%d",&T); the intKase =1; + while(t-- ){ -memset (bit,0,sizeof(bit)); $printf"Case %d:\n", kase++); $scanf"%d%d",&n,&m); - intPTR =0; - for(intI=0; i<n;i++){ thescanf"%d",&A[i].first); -A[i].second = i+1;Wuyi } the for(intI=0; i<m;i++){ -scanf"%d%d%d",&qq[i].ql,&qq[i].qr,&QQ[I].QH); WuQq[i].idx =i; - } About $Sort (qq,qq+m); -Sort (a,a+n); - - intj=0; A for(intI=0; i<m;i++){ + while(J<n && a[j].first<=QQ[I].QH) { theAdd (A[j].second,1); -J + +; $ } theANS[QQ[I].IDX] = SUM (qq[i].qr+1) -sum (QQ[I].QL); the } the the for(intI=0; i<m;i++){ -printf"%d\n", Ans[i]); in } the the } About return 0; the}
[HDU 4417] Super Mario (tree-like array)