bzoj1113

时间:2023-03-09 06:05:22
bzoj1113

传送门: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=,top=,ans=;
for (int i=; i<=n; i++) scanf("%d%d",&a[i],&b[i]),mmax=max(mmax,b[i]);
z[]=;
for (int i=; i<=n; i++)
{
while (z[top]>b[i]) top--;
if (z[top]<b[i]) ans++;
z[++top]=b[i];
}
printf("%d\n",ans);
}