『算法-ACM竞赛』单调栈(模板)

『算法-ACM 竞赛』单调栈(模板)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
a[n + 1] = p = 0;
for (int i = 1; i <= n + 1; i++) {
if (a[i] > s[p]) {
s[++p] = a[i], w[p] = 1;
} else {
int width=0;
while (s[p] > a[i]) {
width += w[p];
ans = max(ans, (long long)width \* s[p]);
p--;
}
s[++p] = a[i], w[p] = width + 1;
}
}



『算法-ACM竞赛』单调栈(模板)
https://chiamzhang.github.io/2024/06/29/『算法-ACM竞赛』单调栈(模板)/
Author
Chiam
Posted on
June 29, 2024
Licensed under