Codeforces - 845D Driving Test

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
11
1 100
3 70
4
2
3 120
5
3 120
6
1 150
4
3 300
output
2
input
5
1 100
3 200
2
4
5
output
0
input
7
1 20
2
6
4
6
6
2
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<<29
using 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;
}









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值