# BZOJ 1628: [Usaco2007 Demo]City skyline (单调栈)

Posted by 111qqz on Monday, April 4, 2016

## 1628: [Usaco2007 Demo]City skyline

Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 396  Solved: 317 [Submit][Status][Discuss]

## Sample Input

10 26 1 1 2 2 5 1 6 3 8 1 11 0 15 2 17 3 20 2 22 1

INPUT DETAILS:

The case mentioned above

## Sample Output

6

``````/* ***********************************************
Author :111qqz
Created Time :2016年04月04日 星期一 15时23分45秒
File Name :code/bzoj/1628.cpp
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define fst first
#define sec second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long LL;
#define pi pair < int ,int >
#define MP make_pair

using namespace std;
const double eps = 1E-8;
const int dx4[4]={1,0,0,-1};
const int dy4[4]={0,-1,1,0};
const int inf = 0x3f3f3f3f;
const int N=1E6+7;
int n,w;
int x[N],y[N];
int st[N];
int main()
{
#ifndef  ONLINE_JUDGE
freopen("code/in.txt","r",stdin);
#endif

ios::sync_with_stdio(false);
cin>>n>>w;
for ( int i = 1 ; i <= n ; i++)
{
cin>>x[i]>>y[i];
}

int top = 0;
int ans = n;
for ( int i = 1 ;i  <= n ; i++)
{
while (top&&y[i]<st[top]) top--;
if (st[top]==y[i]) ans--;
else st[++top] = y[i];
}
cout<<ans<<endl;

#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}
``````