单调栈
C++
int stk[N], tt = 0;
for (int x : nums) {
while (tt > 0 && check(stk[tt], x)) --tt;
stk[++tt] = x;
}
int stk[N], tt = 0;
for (int x : nums) {
while (tt > 0 && check(stk[tt], x)) --tt;
stk[++tt] = x;
}