参考题解https://www.luogu.com.cn/blog/wyy2020/solution-p4755
思路应该是,求出左边和右边最远的 ≤ai 的数,可代码中为什么一个是 ≤ 一个是 <,没懂
for (int i = 1; i <= n; i++) {
while (top && a[stk[top]] < a[i]) top--;
if (top) lef[i] = stk[top] + 1;
stk[++top] = i;
}
top = 0;
for (int i = n; i; i--) {
while (top && a[stk[top]] <= a[i]) top--;
if (top) rig[i] = stk[top] - 1;
stk[++top] = i;
}