您的位置:首页 > 其它

bzoj1113

2016-06-05 16:01 260 查看
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1113

题解:单调栈

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define maxn 250005
using namespace std;
int n;
int a[maxn],b[maxn],z[maxn];
int main()
{
scanf("%d\n",&n);
int mmax=0,top=0,ans=0;
for (int i=1; i<=n; i++) scanf("%d%d",&a[i],&b[i]),mmax=max(mmax,b[i]);
z[0]=0;
for (int i=1; i<=n; i++)
{
while (z[top]>b[i]) top--;
if (z[top]<b[i]) ans++;
z[++top]=b[i];
}
printf("%d\n",ans);
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: