BZOJ1595 [Usaco2008 Jan] Artificial lake

Source: Internet
Author: User

Direct simulation ... Expand from the lowest to the opposite side = =

1 /**************************************************************2 problem:15953 User:rausen4 language:c++5 result:accepted6 time:328 Ms7 memory:3932 KB8 ****************************************************************/9  Ten#include <cstdio> One   A using namespacestd; -typedefLong Longll; - Const intN = 1e5 +5; the Constll inf =(ll) 1e18; -   -Inlineintread (); -   + structData { - ll W, H; +     intPre, NXT; A       atInlinevoid Get(intx) { -W = Read (), h =read (); -Pre = x-1, NXT = x +1; -     } - } A[n]; -   in intN, now; - ll Now_ans, ans[n]; to   + intMain () { -     inti; then =read (); *      for(i = now =1; I <= N; ++i) { $A[i].Get(i);Panax Notoginseng         if(A[i].h < a[now].h) now =i; -     } thea[0].W = A[n +1].W =0, a[0].h = A[n +1].h = inf, a[0].NXT =1, A[n +1].pre =N; + #definePre A[now].pre A #defineNxt A[NOW].NXT the      for(i =1; I <= N; ++i) { +          while(A[pre].h < a[now].h) now =Pre; -          while(A[nxt].h < a[now].h) now =Nxt; $Ans[now] = Now_ans +A[NOW].W; $A[PRE].NXT = NXT, A[nxt].pre =Pre; -         if(A[pre].h <a[nxt].h) { -Now_ans + = A[NOW].W * (A[pre].h-a[now].h); theA[PRE].W + = A[NOW].W, now =Pre; -}Else {WuyiNow_ans + = A[NOW].W * (A[nxt].h-a[now].h); theA[NXT].W + = A[NOW].W, now =Nxt; -         } Wu     } -      for(i =1; I <= N; ++i) Aboutprintf"%lld\n", Ans[i]); $     return 0; - } -   -InlineintRead () { A     Static intx; +     Static Charch; thex =0, ch =GetChar (); -      while(Ch <'0'||'9'<ch) $CH =GetChar (); the      while('0'<= CH && Ch <='9') { thex = x *Ten+ CH-'0'; theCH =GetChar (); the     } -     returnx; in}
View Code

BZOJ1595 [Usaco2008 Jan] Artificial lake

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.