#P9540. 「AWOI Round 2 C」数组操作?数组操作!
「AWOI Round 2 C」数组操作?数组操作!
Problem Description
You are given two arrays of length . Merge them to obtain an array of length .
Let the -th element of array be placed at position in array after merging, and the -th element of array be placed at position in array after merging. After merging, it must satisfy and , meaning the relative order of elements within each array remains unchanged.
After merging, you need to perform the following operations on array :
- Toggle operation: Choose an interval . For each , if equals , change it to a number different from ; otherwise, change it to .
- Reverse operation: Choose an interval and reverse the numbers in this subarray. This operation must be performed exactly times.
Output the minimum number of toggle operations needed to make all numbers in array equal to .
Input Format
The first line contains three integers .
The second line contains integers, representing the elements in array .
The third line contains integers, representing the elements in array .
Output Format
One positive integer, representing the answer.
5 1 1
1 1 45 1 4
1 9 1 9 810
1
20 0 3
1 0 0 8 6 10 0 8 6 1 0 0 86 1 0 0 8 6 0 0
5 2 0 1 3 1 4 52 0 13 14 0 1 0 1 0 4 0 5 0
4
3 2 4
110 105 117
99 108 98
1
Hint
[Sample Explanation]
For sample , let be .
Here, $c_1 = a_1, c_2 = b_1, c_3 = a_2, c_4 = b_2, c_5 = a_3, c_6 = a_4, c_7 = b_3, c_8 = b_4, c_9 = a_5, c_{10} = b_5$. This satisfies the requirements.
Then reverse the interval , and array becomes .
Next, perform a toggle operation to change all numbers in into .
So only one toggle operation is needed at minimum. It can be proven that no strategy is better than this.
[Constraints]
Please note the special time limit of this problem and use faster I/O.
This problem uses bundled testdata.
| Subtask ID | Special Property | Score | |
|---|---|---|---|
| None | |||
| Special Property A | |||
| None |
Special Property A: It is guaranteed that the elements in the two arrays are either all equal to , or all not equal to .
For all testdata, it is guaranteed that , and all input data are within the int range.
Translated by ChatGPT 5