#P14672. [ICPC 2025 Seoul R] CPEquivalence
[ICPC 2025 Seoul R] CPEquivalence
题目描述
Given an integer array consisting of integers (namely, each item of is an integer), the Closest Position array (CP-array) is an array of length defined to be
$$CP(x)[i] = \max(\{j \mid j < i; x[j] \ge x[i]\} \cup \{-1\}) \text{ for all } 0 \le i < |x|,$$where denotes the -th integer in , and the length is the number of integers in . In other words, is the greatest index of that is smaller than and whose item at that index is greater than or equal to . For example, when , its CP-array is , and .
We say that two integer arrays and are CP-equivalent if . It is obvious that two CP-equivalent integer arrays and have the same length. For example, two arrays and are CP-equivalent because their CP-arrays are the same as .
For an integer array , an integer and a non-negative integer , a substitution operation on at position into returns the array $[x[0], x[1], \cdots, x[i-1], a, x[i+1], \cdots, x[|x|-1]]$. For an integer array and a non-negative integer , a deletion operation on at position returns the array $[x[0], x[1], \cdots, x[i-1], x[i+1], \cdots, x[|x|-1]]$. Finally, for an integer array , an integer and a non-negative integer , an insertion operation on at position returns the array $[x[0], x[1], \cdots, x[i-1], a, x[i], \cdots, x[|x|-1]]$. An edit operation on is one of an insertion, a deletion or a substitution at a single position.
Given two integer arrays and , compute the minimum number of edit operations on to obtain an array satisfying .
For example, let and . Consider the array . Then, we have and therefore and are CP-equivalent. Then, we can obtain the integer array applying two edit operations on and it is minimum.
输入格式
Your program is to read from standard input. The input consists of three lines. The first line consists of two integers and (; ) that indicate the length of and , respectively. The second line consists of integers between and (both inclusive), representing the array . The third line consists of integers between and (both inclusive), representing the array .
输出格式
Your program is to write to standard output. Print exactly one line containing the minimum number of edit operations on to obtain an integer array satisfying .
5 5
64 2 5 100 100
3 1 2 4 1
0
5 4
64 2 5 100 100
-5 -5 -5 -5
2
6 5
1 2 3 4 5 6
2 5 3 4 5
3
6 3
1 3 5 2 5 2
5 5 6
3