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 ;}