#P1439. 两个排列的最长公共子序列

两个排列的最长公共子序列

Description

Given two permutations P1P_1 and P2P_2 of 1,2,,n1,2,\ldots,n, find their longest common subsequence.

Input Format

The first line contains an integer nn. Each of the next two lines contains nn integers forming a permutation of 1,2,,n1,2,\ldots,n.

Output Format

A single integer, the length of the longest common subsequence.

5 
3 2 1 4 5
1 2 3 4 5

3

Hint

  • For 50%50\% of the testdata, n103n \le 10^3.
  • For 100%100\% of the testdata, n105n \le 10^5.

Translated by ChatGPT 5