每次有
- 每次遍历到高度比栈顶小的,就出栈,同时,求出当前栈顶矩阵高度下的最大面积
- 在出栈时要设置变量temp,记录每一次出栈后的总和宽度,用于求出当前栈顶矩阵高度下的最大面积,以及新结点进栈后的宽度
- 最后要将遍历完的单调性的栈一个个出栈,仍然要用temp记录出栈的宽度总和,用于求出当前栈顶矩阵高度下的最大面积
void calc(int x){
int top=1,temp=0;
maxs=0;
stack[1].height=pos[x][1];
stack[1].length=1;
for(i=2;i<=m;++i){
temp=0;
while(stack[top].height>=pos[x][i]&&top>0){
temp+=stack[top].length;
maxs=max(maxs,stack[top--].height*temp);
}
stack[++top].height=pos[x][i];
stack[top].length=temp+1;
}
temp=0;
while(top>0){
temp+=stack[top].length;
maxs=max(maxs,stack[top--].height*temp);
}
ans=max(ans,maxs);
}