bzoj1113 [Poi2008]海报PLA

来源:互联网 发布:怎么下载网站的数据库 编辑:程序博客网 时间:2024/05/18 05:03

题目

首先,答案的上界显然就为n。之后考虑如何减少——如果两张海报高度相同,之间的海报都比它高,答案就减少一。

单调队列就可以了。

#include<bits/stdc++.h>#define N 250000using namespace std;int n,tot;int tmp,x;int stk[N+1],top; inline char nc(){    static char buf[100000],*p1=buf,*p2=buf;    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline int read(){    int x=0,b=1;    char c=nc();    for(;!(c<='9'&&c>='0');c=nc())if(c=='-')b=-1;    for(;c<='9'&&c>='0';c=nc())x=x*10+c-'0';    return x*b;}inline void write(int x){    if(x==0)putchar('0');    else    {        char buf[15];        int len=0;        if(x<0)putchar('-'),x=-x;        while(x)buf[++len]=x%10+'0',x/=10;        for(int i=len;i>=1;i--)putchar(buf[i]);    }    putchar(' ');}int main(){    freopen("in.txt","r",stdin);    n=read();    for(int i=1;i<=n;i++)    {        tmp=read(),x=read();        while(x<=stk[top])tot+=(x==stk[top--]);        stk[++top]=x;    }    cout<<n-tot;    return 0;}
原创粉丝点击