4420: P8184 [USACO22FEB] Photoshoot 2 B

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:4 Solved:3

Description

题目描述 In what seems to be a familiar occurrence, Farmer John is lining up his � N cows ( 1 ≤ � ≤ 1 0 5 ) (1≤N≤10 5 ), conveniently numbered 1 ⋯ � 1⋯N, for a photograph. Initially, the cows are lined up in the order � 1 , � 2 , ⋯   , � � a 1 ​ ,a 2 ​ ,⋯,a N ​ from left to right. Farmer John's goal is to line up the cows in the order � 1 , ⋯   , � � b 1 ​ ,⋯,b N ​ from left to right. To accomplish this, he may perform a series of modifications to the ordering. Each modification consists of choosing a single cow and moving it some number of positions to the left. Please count the minimum number of modifications required in order for Farmer John to line up his cows in the desired order. 输入格式 The first line of input contains � N. The second line contains � 1 , � 2 , ⋯   , � � a 1 ​ ,a 2 ​ ,⋯,a N ​ . The third line contains � 1 , ⋯   , � � b 1 ​ ,⋯,b N ​ . 输出格式 Print the minimum number of modifications required to produce Farmer John's desired ordering. 题意翻译 题目描述 在一个似曾相识的场景中,Farmer John 正在将他的 � N 头奶牛 ( 1 ≤ � ≤ 1 0 5 ) (1≤N≤10 5 )排成一排(为了方便将它们按 1 ⋯ � 1⋯N 编号),以便拍照。 最初,奶牛从左到右按照 � 1 , � 2 , ⋯   , � � a 1 ​ ,a 2 ​ ,⋯,a N ​ 的顺序排列。Farmer John 的目标是按照 � 1 , ⋯   , � � b 1 ​ ,⋯,b N ​ 从左到右的顺序排列奶牛。为此,他可以对排列顺序进行一系列修改。每次修改为选择一头奶牛并将其向左移动一些位置。 请计算农民约翰按所需顺序排列奶牛所需的最少修改次数。

Sample Input Copy

5
1 2 3 4 5
1 2 3 4 5

Sample Output Copy

0