problem list
F 蚂蚁
- 刚开始想的是对于序列里面数值大小打标记之类的
- 但是想想复杂度太高
- 用栈来做模拟,选择一个方向push,另一个方向作为pop的判定,中途计算ans
#include <bits/stdc++.h>
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
const int maxn = 1000 + 10 ;
const int inf = 0x3f3f3f3f ;
const int npos = -1 ;
const double eps = 1e-20 ;
int n, a, b, ans;
std::stack< int > s;
int main(){
while(~scanf("%d",&n)){
ans=0;
while(!s.empty()){s.pop();}
for(int i=1;i<=n;i++){
scanf("%d %d",&a,&b);
if(b){
s.push(a);
}else{
while(!s.empty() && s.top()<a){s.pop();}
ans+=s.empty();
}
}
ans+=s.size();
printf("%d\n",ans);
}
return 0;
}