稍微麻烦一点的是对超速的处理问题,用栈保存一下就行。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <queue>
using namespace std;
const int MAXN = 300000+10;
const int INF=1e5+7;
const double eps=1e-8;
const double pi=acos(-1.0);
int que[MAXN];
int main(){
int n;
scanf("%d",&n);
int v=0;//当前速度
int flag=0;//是否允许超车
int vs=INF;//当前限速
int res=0;
int ff=0;
int top=0;
for(int i=0;i<n;i++){
int t;
scanf("%d",&t);
if(t==1){
int s;
scanf("%d",&s);
v=s;
while(top&&que[top]<v){
res++;
top--;
}
}else if(t==2){
if(flag&&ff){
res+=ff;
ff=0;
flag=0;
}
}else if(t==3){
int s;
scanf("%d",&s);
vs=s;
if(v>vs){
res++;
}else{
que[++top]=vs;
}
}else if(t==4){
flag=0;
ff=0;
}else if(t==5){
vs=INF;
if(v>vs){
res++;
}else{
que[++top]=vs;
}
}else if(t==6){
flag=1;
ff+=1;
}
}
printf("%d\n",res);
}