题目链接:1113:[Poi2008]海报PLA
发现只要有一个向上凸起的矩形,就会ans++
所以用一发单调栈维护高度值,宽度并没有什么卵用
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1000010;
int n,m,sta[maxn],a[maxn],ans=0;
int main(){
scanf("%d",&n); int top=0;
for (int i=1;i<=n;++i){
int x,y; scanf("%d%d",&x,&y);
while (top&&y<=sta[top])
{if (y<sta[top])ans++; top--;}
sta[++top]=y;
}
ans+=top; printf("%d",ans);
}