300988: CF187A. Permutations

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Permutations

题意翻译

- 给出两个长度为 $n$ 的排列。 - 每次可以把第一个排列末尾的数移到该排列中的任意位置。 - 问需要多少次操作能使两个排列相等。 - $1 \le n \le 2 \times {10}^5$。

题目描述

Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers $ 1 $ through $ n $ and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation. Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second.

输入输出格式

输入格式


The first line contains a single integer $ n $ ( $ 1<=n<=2·10^{5} $ ) — the quantity of the numbers in the both given permutations. Next line contains $ n $ space-separated integers — the first permutation. Each number between $ 1 $ to $ n $ will appear in the permutation exactly once. Next line describe the second permutation in the same format.

输出格式


Print a single integer denoting the minimum number of moves required to convert the first permutation to the second.

输入输出样例

输入样例 #1

3
3 2 1
1 2 3

输出样例 #1

2

输入样例 #2

5
1 2 3 4 5
1 5 2 3 4

输出样例 #2

1

输入样例 #3

5
1 5 2 3 4
1 2 3 4 5

输出样例 #3

3

说明

In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: - 1 5 2 3 4 - 1 4 5 2 3 - 1 3 4 5 2 - 1 2 3 4 5 So he needs three moves.

Input

题意翻译

- 给出两个长度为 $n$ 的排列。 - 每次可以把第一个排列末尾的数移到该排列中的任意位置。 - 问需要多少次操作能使两个排列相等。 - $1 \le n \le 2 \times {10}^5$。

加入题单

算法标签: