Hdoj 4417 Super Mario

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4417

Your sister's CIN cout scanf printf. It's far behind. Cin cout will wa But scanf printf will be AC ..

I learned about the magic operation of eaual_range ..

It is a line segment tree, and the vector is very powerful ..

View code

# Include <iostream> # Include <Cstdio> # Include <Algorithm> # Include <Vector> # Define Lson L, M, root <1 # Define Rson m + 1, R, root <1 | 1 Using   Namespace  STD; Const   Int Maxn = 100001  ; Typedef Vector < Int > VI; typedef pair <VI: iterator, VI: iterator> PII;  Int  H [maxn]; VI tree [maxn * 4  ];  Int  N, m;  Void Build (Int L, Int R, Int  Root) {tree [root]. Clear ();  For ( Int I = L; I <= r; I ++ ) Tree [root]. push_back (H [I]); sort (tree [root]. Begin (), tree [root]. End ());  If (L = r) Return  ;  Int M = (L + r)> 1  ; Build (lson); Build (rson );} Int Query ( Int Ll, Int RR, Int H, Int L, Int R, Int  Root ){  If (Ll <= L & R <= Rr) {PII result; Result = Performance_range (tree [root]. Begin (), tree [root]. End (), H );  Return Result. Second-Tree [root]. Begin ();}  Int Ans = 0  ;  Int M = (L + r)> 1  ;  If (Ll <= M) ans = Query (LL, RR, H, lson );  If (Rr> M) ans + = Query (LL, RR, H, rson );  Return Ans ;}  Void  Solve (){  Int  L, R, h;  For ( Int J = 1 ; J <= m; j ++ ) {Scanf (  "  % D  " , & L, & R ,& H); printf (  "  % D \ n " , Query (L, R, H, 0 , N- 1 , 1  ));}}  Int  Main (){  Int  Test; scanf (  "  % D  " ,& Test );  For ( Int I =1 ; I <= test; I ++ ) {Scanf (  "  % D  " , & N ,& M );  For ( Int J = 0 ; J <n; j ++ ) Scanf (  "  % D  " ,& H [J]); printf (  " Case % d: \ n  "  , I); Build (  0 , N- 1 , 1  ); Solve ();}  Return   0  ;} 

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.