#P9540. 「AWOI Round 2 C」数组操作?数组操作!

「AWOI Round 2 C」数组操作?数组操作!

Problem Description

You are given two arrays a,ba, b of length nn. Merge them to obtain an array cc of length 2×n2 \times n.

Let the ii-th element of array aa be placed at position lbilb_i in array cc after merging, and the ii-th element of array bb be placed at position lcilc_i in array cc after merging. After merging, it must satisfy lb1<lb2<<lbn1<lbnlb_1 < lb_2 < \dots < lb_{n-1} < lb_n and lc1<lc2<<lcn1<lcnlc_1 < lc_2 < \dots < lc_{n-1} < lc_n, meaning the relative order of elements within each array remains unchanged.

After merging, you need to perform the following operations on array cc:

  1. Toggle operation: Choose an interval [l,r][l, r]. For each i[l,r]i \in [l, r], if cic_i equals yy, change it to a number different from yy; otherwise, change it to yy.
  2. Reverse operation: Choose an interval [l,r][l, r] and reverse the numbers in this subarray. This operation must be performed exactly zz times.

Output the minimum number of toggle operations needed to make all numbers in array cc equal to yy.

Input Format

The first line contains three integers n,y,zn, y, z.

The second line contains nn integers, representing the elements in array aa.

The third line contains nn integers, representing the elements in array bb.

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 11, let cc be {1,1,1,9,45,1,1,9,4,810}\{1, 1, 1, 9, 45, 1, 1, 9, 4, 810\}.

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 [4,7][4, 7], and array cc becomes {1,1,1,1,1,45,9,9,4,810}\{1, 1, 1, 1, 1, 45, 9, 9, 4, 810\}.

Next, perform a toggle operation to change all numbers in [6,10][6, 10] into 11.

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 nn \leqslant Special Property Score
11 55 None 2020
22 10610^6 z>nz > n 55
33 Special Property A 1010
44 z=0z = 0 2525
55 None 4040

Special Property A: It is guaranteed that the elements in the two arrays are either all equal to yy, or all not equal to yy.

For all testdata, it is guaranteed that 0y,z1090 \leqslant y, z \leqslant 10^9, and all input data are within the int range.

Translated by ChatGPT 5