[BZOJ1113][Poi2008]海报PLA(单调栈)

来源:互联网 发布:linux查看日志命令tail 编辑:程序博客网 时间:2024/04/30 02:02

题目描述

传送门

题解

确实这也叫单调栈。

代码

#include<iostream>#include<cstring>#include<cstdio>using namespace std;int strack[250005];int n,x,y,temp,ans;int main(){    scanf("%d",&n);    for (int i=1;i<=n;++i){        scanf("%d%d",&x,&y);        while (y<=strack[temp]){            if (strack[temp]==y) ans++;            temp--;        }        strack[++temp]=y;    }    printf("%d\n",n-ans);}
0 0