1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
| #include <cstdio>
#include <algorithm>
struct Link
{
int lef, rig, hgt;
Link *left, *right;
} a[100002];
int n, lowest(0x3FFFFFFF);
long long drop[100001], ans;
Link *now;
int main()
{
scanf("%d", &n);
a[0].lef = a[0].rig = 0, a[0].hgt = 0x3FFFFFFF, a[0].left = NULL, a[0].right = a+1;
for (int i = 1, w, h; i <= n; ++i)
{
scanf("%d%d", &w, &h);
a[i].lef = a[i-1].rig, a[i].rig = a[i].lef+w, a[i].hgt = h;
a[i].left = a+i-1, a[i].right = a+i+1;
if (h < lowest)
{
lowest = h;
now = a+i;
}
}
a[n+1].lef = a[n+1].rig = a[n].rig, a[n+1].hgt = 0x3FFFFFFF, a[n+1].left = a+n, a[n+1].right = NULL;
for (Link *lower, *next; now->left && now->right; now = next)
{
if (now->left->hgt < now->right->hgt)
{
for (next = now->left; next->left != NULL && next->left->hgt <= next->hgt; next = next->left);
lower = now->left;
}
else
{
for (next = now->right; next->right != NULL && next->right->hgt <= next->hgt; next = next->right);
lower = now->right;
}
drop[now-a] = ans + now->right->lef - now->left->rig;
ans += static_cast<long long>(now->right->lef - now->left->rig)*(lower->hgt - now->hgt);
now->left->right = now->right;
now->right->left = now->left;
}
for (int i = 1; i <= n; ++i)
printf("%I64dn", drop[i]);
}
|