306683: CF1237B. Balanced Tunnel

Memory Limit:512 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Balanced Tunnel

题意翻译

想象一下我们有一个单向的隧道。在某一天当中,有$n$辆车(编号分别为$1 \sim n$)进出隧道恰好一次。在通过隧道的时候,每一辆车都要按照恒定的速度行驶。 在隧道入口和出口分别有一个交通执法摄像机。**完美平衡!!!** 由于这两台摄像机的存在,我们知道这$n$辆车进入隧道的顺序和离开隧道的顺序,而且没有两辆车会同时进入或者同时离开隧道。 交通法中禁止在隧道超车,如果汽车$i$在隧道中超过了任何一个汽车$j$,那么汽车$i$就要受到罚款。但是每一辆车最多只会受到一次罚款。 所以我们会发现,如果汽车$i$比汽车$j$晚进入隧道,但是却比汽车$j$早离开隧道,汽车$i$一定是在隧道当中超过了汽车$j$。同时,我们只会对的确在隧道中超过其他汽车($\ge1$次)的汽车进行罚款。 现在我们想要知道一共需要对几辆汽车进行罚款。 ------ **简洁题面:** 先给你一个$n$,之后给你$n$个数构成序列$a$,他们的顺序是固定的。 再给出$n$个数构成序列$b$。 对于一对$i, j$,如果在序列$a$中$j$在$i$之前,但是在序列$b$中$i$却在$j$之前,$i$就要被标记。 但是对于每一个数$i$,他最多会被标记。 现在请你求出一共有多少个数需要被标记。

题目描述

Consider a tunnel on a one-way road. During a particular day, $ n $ cars numbered from $ 1 $ to $ n $ entered and exited the tunnel exactly once. All the cars passed through the tunnel at constant speeds. A traffic enforcement camera is mounted at the tunnel entrance. Another traffic enforcement camera is mounted at the tunnel exit. Perfectly balanced. Thanks to the cameras, the order in which the cars entered and exited the tunnel is known. No two cars entered or exited at the same time. Traffic regulations prohibit overtaking inside the tunnel. If car $ i $ overtakes any other car $ j $ inside the tunnel, car $ i $ must be fined. However, each car can be fined at most once. Formally, let's say that car $ i $ definitely overtook car $ j $ if car $ i $ entered the tunnel later than car $ j $ and exited the tunnel earlier than car $ j $ . Then, car $ i $ must be fined if and only if it definitely overtook at least one other car. Find the number of cars that must be fined.

输入输出格式

输入格式


The first line contains a single integer $ n $ ( $ 2 \le n \le 10^5 $ ), denoting the number of cars. The second line contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 1 \le a_i \le n $ ), denoting the ids of cars in order of entering the tunnel. All $ a_i $ are pairwise distinct. The third line contains $ n $ integers $ b_1, b_2, \ldots, b_n $ ( $ 1 \le b_i \le n $ ), denoting the ids of cars in order of exiting the tunnel. All $ b_i $ are pairwise distinct.

输出格式


Output the number of cars to be fined.

输入输出样例

输入样例 #1

5
3 5 2 1 4
4 3 2 5 1

输出样例 #1

2

输入样例 #2

7
5 2 3 6 7 1 4
2 3 6 7 1 4 5

输出样例 #2

6

输入样例 #3

2
1 2
1 2

输出样例 #3

0

说明

The first example is depicted below: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1237B/7d2f6b4d3eea560d8fb835871b9aa0fd74a81766.png) Car $ 2 $ definitely overtook car $ 5 $ , while car $ 4 $ definitely overtook cars $ 1 $ , $ 2 $ , $ 3 $ and $ 5 $ . Cars $ 2 $ and $ 4 $ must be fined. In the second example car $ 5 $ was definitely overtaken by all other cars. In the third example no car must be fined.

Input

题意翻译

想象一下我们有一个单向的隧道。在某一天当中,有$n$辆车(编号分别为$1 \sim n$)进出隧道恰好一次。在通过隧道的时候,每一辆车都要按照恒定的速度行驶。 在隧道入口和出口分别有一个交通执法摄像机。**完美平衡!!!** 由于这两台摄像机的存在,我们知道这$n$辆车进入隧道的顺序和离开隧道的顺序,而且没有两辆车会同时进入或者同时离开隧道。 交通法中禁止在隧道超车,如果汽车$i$在隧道中超过了任何一个汽车$j$,那么汽车$i$就要受到罚款。但是每一辆车最多只会受到一次罚款。 所以我们会发现,如果汽车$i$比汽车$j$晚进入隧道,但是却比汽车$j$早离开隧道,汽车$i$一定是在隧道当中超过了汽车$j$。同时,我们只会对的确在隧道中超过其他汽车($\ge1$次)的汽车进行罚款。 现在我们想要知道一共需要对几辆汽车进行罚款。 ------ **简洁题面:** 先给你一个$n$,之后给你$n$个数构成序列$a$,他们的顺序是固定的。 再给出$n$个数构成序列$b$。 对于一对$i, j$,如果在序列$a$中$j$在$i$之前,但是在序列$b$中$i$却在$j$之前,$i$就要被标记。 但是对于每一个数$i$,他最多会被标记。 现在请你求出一共有多少个数需要被标记。

加入题单

算法标签: