• Source
    1. /**************************************************************
    2.   Problem: 1113
    3.   User: zrts
    4.   Language: C++
    5.   Result: Accepted
    6.   Time:1496 ms
    7.   Memory:1780 kb
    8. ****************************************************************/
    9.  
    10. #include<cstdio>
    11. #include<cstring>
    12. #include<algorithm>
    13. //by zrt
    14. //problem:
    15. using namespace std;
    16. typedef long long ll;
    17. const double eps(1e-10);
    18. int stk[250005],top;
    19. int main(){
    20. #ifdef LOCAL
    21. freopen("in.txt","r",stdin);
    22. freopen("out.txt","w",stdout);
    23. #endif
    24. int n;
    25. scanf("%d",&n);
    26. int ans=0;
    27. for(int i=0,x;i<n;i++){
    28. scanf("%*d%d",&x);
    29. while(top>0&&x<=stk[top-1]) {
    30. top--,ans++;
    31. if(stk[top]==x) ans--;
    32. }
    33. stk[top++]=x;
    34. }
    35. printf("%d\n",ans+top);
    36. return 0;
    37. }