单调递增栈:栈顶到栈底为递增,数据出栈的序列为单调递增序列
单调递减栈:栈顶到栈底为递减,数据出栈的序列为单调递减序列
栈内可存储下标,也可存储元素
\(code :\)
for(int i=1;i<=n;++i) { while(top&&a[i]>a[st[top]]) top--; st[++top]=i; }
单调栈
原文:https://www.cnblogs.com/lhm-/p/12229599.html