#P4098. [HEOI2013] ALO

    ID: 3034 远端评测题 1000ms 128MiB 尝试: 1 已通过: 0 难度: 8 上传者: 标签>2013各省省选河北枚举,暴力可持久化字典树,Trie 树

[HEOI2013] ALO

Description

Welcome to ALO (Arithmetic and Logistic Online). This is a VR MMORPG. As the name suggests, it is full of math puzzles.

You have nn gems. The ii-th gem has an energy density aia_i, and all energy densities are pairwise distinct. You may select a contiguous segment of gems (with at least two gems) to fuse. Suppose their energy densities are ai,ai+1,,aja_i, a_{i+1}, \cdots, a_j. The fused gem’s energy density is the maximum value of the bitwise XOR between the second largest energy density in this segment and any other gem in the same segment. That is, if the second largest in this segment is kk, the generated energy density equals $\max\{k \oplus a_p \mid a_p \ne k,\ i \le p \le j\}$.

Find how to choose the segment to maximize the fused gem’s energy density.

Input Format

The first line contains an integer nn, the number of gems.

The second line contains nn integers, a1a_1 through ana_n, the energy density of each gem. It is guaranteed that for iji \ne j we have aiaja_i \ne a_j.

Output Format

Output one integer, the maximum possible fused gem energy density.

5 
9 2 1 4 7
14

Hint

Sample Explanation

Choose the segment [1,5][1, 5]. The maximum is 79=147 \oplus 9 = 14.

Constraints

  • For 20%20\% of the testdata, n100n \le 100.
  • For 50%50\% of the testdata, n2000n \le 2000.
  • For 100%100\% of the testdata, 1n500001 \le n \le 50000, 0ai1090 \le a_i \le 10^9.

2023-04-28: Added two hack testdata, not scored.

Translated by ChatGPT 5