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