#P12568. [UOI 2023] An Array and Range Additions

[UOI 2023] An Array and Range Additions

题目描述

Given an array of integers aa of length nn.

You can modify the array using the addition operation. To apply the addition operation, you need to perform three sequential actions:

  • Choose any integer xx.
  • Choose any subarray [l;r][l;r] of the array.
  • Add xx to each element of the chosen subarray (perform the assignment operation ai(ai+x)a_i \leftarrow (a_i+x) for lirl \le i\le r).

Find the minimum number of addition operations required to make all elements of the array aa pairwise distinct.

输入格式

The first line contains a single integer nn (1n21051 \le n \le 2 \cdot 10^5) --- the length of the array.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (1ai1091 \le a_i \le 10^9) --- the elements of the array.

输出格式

Output a single integer --- the minimum number of addition operations required to make all elements of the array aa pairwise distinct.

3
1 2 3
0
5
2 3 2 3 2
2
9
2 3 1 1 3 2 1 3 3
2

提示

In the first example, all elements of the array aa are pairwise distinct.

In the second example, after applying two \textit{addition operations} with parameters x=3x=-3, l=1l=1, r=2r=2 and x=1x=-1, l=1l=1, r=3r=3, the array aa becomes equal to [2,1,1,3,2][-2,-1,1,3,2].

In the third example, after applying two \textit{addition operations} with parameters x=3x=-3, l=4l=4, r=8r=8 and x=10x=-10, l=7l=7, r=9r=9, the array aa becomes equal to [2,3,1,2,0,1,12,10,7][2,3,1,-2,0,-1,-12,-10,-7].

Scoring

  • (99 points): all elements of the array aa are equal to 11.
  • (1515 points): 1ai21 \le a_i \le 2 for 1in1 \le i \le n; aiai+1a_i \le a_{i+1} for 1i<n1 \le i < n.
  • (1414 points): n8n \le 8.
  • (1717 points): a1=ana_1 = a_n.
  • (1212 points): n2000n \le 2000.
  • (1212 points): 1ai1001 \le a_i \le 100 for 1in1\le i\le n.
  • (2121 points): no additional constraints.