51nod 1289 大鱼吃小鱼

#include<bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int a[maxn],b[maxn];
stack<int>s;
int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i];
    int ans =0;
    for(int i=1;i<=n;i++)
    {
        ans++;
        if(b[i] )
            s.push(a[i]);
        else {
            while(!s.empty() && a[i] > s.top() )
            {
                ans--;
                s.pop();
            }
            if(!s.empty() && a[i] < s.top())
            {
                ans--;
            }
        }
    }
    cout<< ans<<endl;
}

 



posted @ 2017-09-14 18:26  Draymonder  阅读(193)  评论(0编辑  收藏  举报