Artificial Lake
Time Limit: 3000MS |
|
Memory Limit: 65536K |
Total Submissions: 1862 |
|
Accepted: 625 |
Description
The oppressively hot summer days has raised the cows ' clamoring to their highest level. Farmer John had finally decided to build a artificial lake. For him engineering studies, he is modeling the lake as a two-dimensional landscape consisting of a contiguous sequence of n soon-to-be-submerged levels (1≤ n ≤100,000) conveniently numbered 1.. N from left to right.
Each level I was described by the integers, its width wi (1≤ wi ≤1,000) and height (like a rel ative elevation) hi (1≤ hi ≤1,000,000). The heights of FJ ' s levels are unique. An infinitely tall barrier encloses the lake's model on the left and right. One example Lake profile is shown below.
* * :
* * :
* * 8
* * * * 7
* * * * 6
* * * * 5
* ********** 4 <-Height
* ********** 3
2
1
Level | 1 |2| 3 |
In FJ's model, he starts filling his lake for sunrise by flowing water to the bottom of the lowest elevation at a rate of 1 square unit of water per minute. The water falls directly downward until it hits something, and then it flows and spreads as room-temperature water always Does. As in all good models, assume that falling and flowing happen instantly. Determine the time at which each elevation ' s becomes submerged by a single unit of water.
Water Water Overflows
| |
* | * * | * * *
* V * * v * * *
* * * .... * *~~~~~~~~~~~~*
* ** * *~~~~** : * *~~~~**~~~~~~*
* ** * *~~~~** : * *~~~~**~~~~~~*
* ** * *~~~~**~~~~~~* *~~~~**~~~~~~*
* ********* *~~~~********* *~~~~*********
*~~~~********* *~~~~********* *~~~~*********
************** ************** **************
************** ************** **************
After 4 mins after- mins after mins
Lvl 1 Submerged lvl 3 submerged lvl 2 submerged
Warning:the answer won't always fit in + bits.
Input
* Line 1: A single integer: N
* Lines 2. N+1:line I+1 describes level i with space-separated integers: Wi and Hi
Output
* Lines 1. N: Line i contains a single integer that's the number of minutes that since sunrise if level #i is covered by water of height 1.
Sample Input
34 22 76 4
Sample Output
45026
Source
Usaco January Gold This problem is actually a not purely meaningful simulation. Starting with the lowest platform and then pouring up, there are so many things that we can't even judge. We can think upside down that we can know the volume (i.e. time) when the water level fills up to +1 of the height of the highest platform. Then we record this answer, break this large interval into two cells, and then process the interval away from the lowest platform (that is, the water injection), and repeat the process. Find the highest platform we can use RMQ pretreatment. Time complexity O (nlog2n).
#include <cstdio>#include<cstring>using namespacestd;Const intMAXN =100005;intN;intd[maxn][ -], num[maxn][ -], W[MAXN], H[MAXN];int_high, _num, MINT, Minn;Long LongSUM[MAXN];Long LongANS[MAXN];Long LongT;voidinit () {sum[0] = w[0] =0; Mint=0x7fffffff; for(inti =1; I <= N; ++i) Sum[i] + = sum[i-1]; for(inti =1; I <= N; ++i) W[i] + = w[i-1]; for(inti =1; I <= N; ++i)if(Mint >H[i]) {Mint=H[i]; Minn=i; } for(intj =1; (1<< j) <= N; ++j) for(inti =1; i + (1<< (J-1)) <= N; ++i) {intother = D[i + (1<< (J-1))][j-1]; if(D[i][j-1] <Other ) {D[i][j]=Other ; NUM[I][J]= Num[i + (1<< (J-1))][j-1]; } Else{D[i][j]= D[i][j-1]; NUM[I][J]= Num[i][j-1]; } }}voidFindout (intLintR) { if(L = =R) {_high=H[l]; _num=L; return; } intK =0; while((1<< (k +1)) <= (R-l +1)) k++; if(D[l][k] > D[r-(1<< k) +1][k]) {_high=D[l][k]; _num=Num[l][k]; } Else{_high= D[r-(1<< k) +1][k]; _num= Num[r-(1<< k) +1][k]; }}intAbsintx) { returnX <0? -x:x;}voidSolveintLintRintlasth) { if(L > R)return; Findout (l, R); T-= (Long Long) (W[r]-w[l-1]) * (Long Long) (Lasth-h[_num]-1); Ans[_num]=T; T-= W[r]-w[l-1]; intTnum = _num, thigh =_high; if(l <= Minn && Minn <= Tnum-1) {Solve (Tnum+1, R, thigh); Solve (l, Tnum-1, thigh); } Else if(Tnum +1<= MINN && Minn <=R) {solve (L, Tnum-1, thigh); Solve (Tnum+1, R, thigh); } Else if(ABS (L-minn) > abs (R-Minn)) {Solve (L, Tnum-1, thigh); Solve (Tnum+1, R, thigh); } Else{Solve (Tnum+1, R, thigh); Solve (l, Tnum-1, thigh); }}intMain () {scanf ("%d", &N); memset (d,0,sizeof(d)); for(inti =1; I <= N; ++i) {scanf ("%d%d", &w[i], &H[i]); d[i][0] =H[i]; num[i][0] =i; Sum[i]= (Long Long) W[i] *H[i]; } init (); Findout (1, N); T= (Long Long) W[n] * (Long Long) (_high +1) -Sum[n]; Solve (1, N, _high +1); for(inti =1; I <= N; ++i) printf ("%i64d\n", Ans[i]); return 0;}
"POJ 3658" Artificial Lake