#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define maxn 110000
#define ll long long
#define inf 1000000000000
ll ans[maxn],last[maxn],next[maxn],w[maxn],h[maxn];
int main ()
{
int i,j,k,n;
scanf("%d",&n);
w[0]=0;
h[0]=inf;
w[n+1]=0;
h[n+1]=inf;
k=0;
for (i=1;i<=n;i++)
{
scanf("%d%d",&w[i],&h[i]);
last[i]=i-1;
next[i-1]=i;
next[i]=i+1;
last[i+1]=i;
if (h[i]<h[k])
{
k=i;
}
}
ll now=0;
for (j=1;j<=n;j++)
{
while ((h[last[k]]<h[k])||(h[next[k]]<h[k]))
{
if (h[last[k]]<h[k])
{
k=last[k];
}
else k=next[k];
}
ans[k]=now+w[k];
last[next[k]]=last[k];
next[last[k]]=next[k];
if( h[last[k]]<h[next[k]] )
{
now=now+w[k]*(h[last[k]]-h[k]);
w[last[k]]=w[last[k]]+w[k];
k=last[k];
}
else
{
now=now+w[k]*(h[next[k]]-h[k]);
w[next[k]]=w[next[k]]+w[k];
k=next[k];
}
}
for(i=1 ;i<= n ;i++)
printf("%lld\n",ans[i]);
return 0;
}
poj3658 模拟
最新推荐文章于 2020-07-15 17:33:08 发布