BZOJ P1113 「POI2008」海報PLA【單調棧】
阿新 • • 發佈:2018-12-13
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define ll long long #define rep(i,x,y) for(ll i=(x);i<=(y);i++) #define repl(i,x,y) for(ll i=(x);i<(y);i++) #define repd(i,x,y) for(ll i=(x);i>=(y);i--) using namespace std; const ll N=3e6+5; ll n,cnt,top,stack[N]; inline ll read() { ll x=0;char ch=getchar();bool f=0; while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();} return f?-x:x; } int main() { n=read(); rep(i,1,n) { ll x=read(),y=read(); while(y<=stack[top]) cnt+=(y==stack[top--]); stack[++top]=y; } printf("%lld\n",n-cnt); return 0; }