Codeforces

来源:互联网 发布:编程 开发 编辑:程序博客网 时间:2024/06/05 12:46

Driving Test

Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types.

  • speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type);
  • overtake is allowed: this sign means that after some car meets it, it can overtake any other car;
  • no speed limit: this sign cancels speed limit if any (car can move with arbitrary speed after this sign);
  • no overtake allowed: some car can't overtake any other car after this sign.

Polycarp goes past the signs consequentially, each new sign cancels the action of all the previous signs of it's kind (speed limit/overtake). It is possible that two or more "no overtake allowed" signs go one after another with zero "overtake is allowed" signs between them. It works with "no speed limit" and "overtake is allowed" signs as well.

In the beginning of the ride overtake is allowed and there is no speed limit.

You are given the sequence of events in chronological order — events which happened to Polycarp during the ride. There are events of following types:

  1. Polycarp changes the speed of his car to specified (this event comes with a positive integer number);
  2. Polycarp's car overtakes the other car;
  3. Polycarp's car goes past the "speed limit" sign (this sign comes with a positive integer);
  4. Polycarp's car goes past the "overtake is allowed" sign;
  5. Polycarp's car goes past the "no speed limit";
  6. Polycarp's car goes past the "no overtake allowed";

It is guaranteed that the first event in chronological order is the event of type 1 (Polycarp changed the speed of his car to specified).

After the exam Polycarp can justify his rule violations by telling the driving instructor that he just didn't notice some of the signs. What is the minimal number of signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view?

Input

The first line contains one integer number n (1 ≤ n ≤ 2·105) — number of events.

Each of the next n lines starts with integer t (1 ≤ t ≤ 6) — the type of the event.

An integer s (1 ≤ s ≤ 300) follows in the query of the first and the third type (if it is the query of first type, then it's new speed of Polycarp's car, if it is the query of third type, then it's new speed limit).

It is guaranteed that the first event in chronological order is the event of type 1 (Polycarp changed the speed of his car to specified).

Output

Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view.

Examples
input
111 1003 70423 12053 12061 15043 300
output
2
input
51 1003 200245
output
0
input
71 20264662
output
2
Note

In the first example Polycarp should say he didn't notice the "speed limit" sign with the limit of 70 and the second "speed limit" sign with the limit of 120.

In the second example Polycarp didn't make any rule violation.

In the third example Polycarp should say he didn't notice both "no overtake allowed" that came after "overtake is allowed" sign.




题意:给你一串行驶指令,问你要最少要忽略多少个指令,才能使考试及格。



解题思路:哇,一开始以为改变速度和超车也是一个sign,但其实不是!!题目问的是要忽略多少个sign,但超车和改变速度指令不算sign,所以直接贪心就好了!那些会使你挂科的指令全部都要忽略掉!详见代码!




#include<iostream>#include<deque>#include<memory.h>#include<stdio.h>#include<map>#include<string>#include<algorithm>#include<vector>#include<math.h>#include<stack>#include<queue>#include<set>#define INF 1<<29using namespace std;int main(){    int n;    scanf("%d",&n);    int v,tv;//当前速度和临时变量    int ans=0;//答案    int tmp=0;//保存在你超车前有多少个不准超车指令    vector<int> vec;//限速指令列表    for(int i=0;i<n;i++){        int k;        scanf("%d",&k);        if(k==1){            scanf("%d",&tv);            v=tv;//改变速度            //看一下你前面有多少个限速指令比你的速度小的            while(!vec.empty()&&vec.back()<v){                ans++;                vec.pop_back();            }        }        if(k==2){            ans+=tmp;//看看前面有多少个不准超车指令            tmp=0;        }        if(k==3){            scanf("%d",&tv);            vec.push_back(tv);            //看看这个限速牌符不符合你的速度            while(!vec.empty()&&vec.back()<v){                ans++;                vec.pop_back();            }        }        if(k==4)//一旦给你超车,前面的不准超车指令数要置0            tmp=0;                if(k==5)//无速度限制,清空限速指令列表            vec.clear();        if(k==6)            tmp++;    }    cout<<ans<<endl;    return 0;}







原创粉丝点击