BZOJ 1113 海报

Posted on 2016-04-29 19:32  ziliuziliu  阅读(113)  评论(0编辑  收藏  举报

单调栈维护。

#include<iostream>
#include<cstdio>
using namespace std;
int t,x,n,s[250001],top,ans;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
       scanf("%d%d",&t,&x);
       while(x<=s[top])
       {
           if(x==s[top])ans++;
           top--;
       }
       s[++top]=x;
    }
    printf("%d",n-ans);
    return 0;
}