单调栈
答案最多为 n n <script type="math/tex" id="MathJax-Element-4">n</script>。容易发现当一个峰的左右有高度相等的两张海报时可以减少一张。那么单调栈维护一个递增的高度即可。
代码:
#include<cctype>
#include<cstdio>
#define N 250005
using namespace std;
int n,stk[N],tp,ans;
inline char readc(){
static char buf[100000],*l=buf,*r=buf;
if (l==r) r=(l=buf)+fread(buf,1,100000,stdin);
return l==r?EOF:*l++;
}
inline int _read(){
int x=0; char ch=readc();
while (!isdigit(ch)) ch=readc();
while (isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=readc();
return x;
}
int main(){
n=_read();
for (int i=1,x;i<=n;i++){
_read(),x=_read();
while (tp&&stk[tp]>x) tp--;
if (stk[tp]==x) ans++;
stk[++tp]=x;
}
return printf("%d\n",n-ans),0;
}