[HDU 4417] Super Mario (tree-like array)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.