#P16787. [蓝桥杯 2026 国 A] 生态廊道
[蓝桥杯 2026 国 A] 生态廊道
Problem Description
An ecological conservation project is assessing the connectivity of an ecological corridor. The project hopes to improve the cooperative interaction between different regions by optimizing the layout of local monitoring sites.
The corridor consists of monitoring sites arranged in a line. The -th site is assigned a genetic diversity code based on its vegetation coverage and water source distribution.
To evaluate the construction quality of the corridor, the expert group defines an indicator called “interaction intensity”. This intensity is given by the sum of the bitwise XOR of codes of all adjacent sites:
$$(a_1 \oplus a_2) + (a_2 \oplus a_3) + \dots + (a_{n-1} \oplus a_n)$$Research shows that the larger the code difference (XOR value) between adjacent sites is, the more active gene exchange becomes during species migration.
In the later optimization stage of the project, engineers may choose two non-overlapping consecutive segments of length on the whole line (only once), and rearrange the three sites within each segment (i.e., change their internal order). The order after rearrangement may be the same as the original.
If the starting indices of the two chosen segments are and , then they must satisfy:
- ;
- .
Now, please help the engineers design the best local adjustment plan, and compute the maximum possible cooperative interaction intensity of the corridor after optimization.
Input Format
The first line contains a positive integer , representing the number of monitoring sites.
The second line contains integers , representing the initial genetic diversity codes of the monitoring sites.
Output Format
Output one integer, representing the maximum cooperative interaction intensity after optimization.
7
1 2 3 4 5 6 7
26
Hint
[Sample Explanation]
You can choose two length segments with starting positions and .
Rearrange the numbers from position to position from to , and keep the numbers from position to position as . The sequence becomes:
The interaction intensity is:
$$(1 \oplus 2) + (2 \oplus 4) + (4 \oplus 3) + (3 \oplus 5) + (5 \oplus 6) + (6 \oplus 7) = 26.$$It can be proven that no larger interaction intensity can be obtained, so the answer is .
[Constraints and Notes on Testdata]
For of the testdata, .
For all testdata, , .
Translated by ChatGPT 5