CF845D.Driving Test
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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:
- Polycarp changes the speed of his car to specified (this event comes with a positive integer number);
- Polycarp's car overtakes the other car;
- Polycarp's car goes past the "speed limit" sign (this sign comes with a positive integer);
- Polycarp's car goes past the "overtake is allowed" sign;
- Polycarp's car goes past the "no speed limit";
- 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?
波利卡普刚刚尝试通过驾驶考试。他沿着一条笔直的道路行驶,途中遇到了四种类型的交通标志:
- 限速标志:该标志附带一个正整数——表示车辆经过此标志后允许的最高速度(取消此前同类型标志的作用);
- 允许超车标志:该标志表示,当某辆车遇到它之后,即可超越任何其他车辆;
- 解除限速标志:该标志取消当前生效的限速(车辆经过此标志后可任意速度行驶);
- 禁止超车标志:该标志表示,某辆车经过此标志后,不得超越任何其他车辆。
波利卡普按顺序依次经过这些标志;每个新出现的同类型标志(限速/允许超车)均会取消此前所有同类型标志的作用。可能出现两个或多个“禁止超车”标志连续出现,且中间没有“允许超车”标志;“解除限速”与“允许超车”标志也遵循同样的规则。
在行程开始时,允许超车,且无速度限制。
现给出按时间顺序排列的一系列事件——即波利卡普在行驶过程中实际发生的事件。事件类型如下:
- 波利卡普将其车速调整为指定值(该事件附带一个正整数);
- 波利卡普的车超越了另一辆车;
- 波利卡普的车经过一个限速标志(该标志附带一个正整数);
- 波利卡普的车经过一个允许超车标志;
- 波利卡普的车经过一个解除限速标志;
- 波利卡普的车经过一个禁止超车标志。
题目保证:按时间顺序排列的第一个事件必为第 1 类事件(波利卡普将车速调整为指定值)。
考试结束后,波利卡普可通过向考官申明自己“未注意到某些标志”,从而对自身违规行为进行辩解。问:波利卡普至少需要声称自己未注意到多少个标志,才能使其从自身视角看来全程未发生任何违规行为?
输入格式
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).
第一行包含一个整数 $ n ( 1 \leq n \leq 2 \cdot 10^5 $)——事件的数量。
接下来的 $ n $ 行中,每行以一个整数 $ t ( 1 \leq t \leq 6 $)开头——表示事件类型。
对于第 1 类和第 3 类查询,其后跟一个整数 $ s ( 1 \leq s \leq 300 $):若为第 1 类查询,则 $ s $ 表示 Polycarp 汽车的新速度;若为第 3 类查询,则 $ s $ 表示新的速度限制。
保证按时间顺序排列的第一个事件为第 1 类事件(Polycarp 将其汽车速度更改为指定值)。
输出格式
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.
输出 Polycarp 需要声称自己未注意到的最少路标数量,使得从他的角度来看,他不会违反任何规则。
输入输出样例
输入#1
11 1 100 3 70 4 2 3 120 5 3 120 6 1 150 4 3 300
输出#1
2
输入#2
5 1 100 3 200 2 4 5
输出#2
0
输入#3
7 1 20 2 6 4 6 6 2
输出#3
2
说明/提示
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.
在第一个例子中,Polycarp 应当声称自己未注意到限速为 70 的“限速”标志以及限速为 120 的第二个“限速”标志。
在第二个例子中,Polycarp 未违反任何规则。
在第三个例子中,Polycarp 应当声称自己未注意到在“允许超车”标志之后出现的两个“禁止超车”标志。
输入解题思路,AI测评打分。不知道怎么写?