CF811C.Vladik and Memorable Trip

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:

Vladik is at initial train station, and now nn people (including Vladik) want to get on the train. They are already lined up in some order, and for each of them the city code aia_{i} is known (the code of the city in which they are going to).

Train chief selects some number of disjoint segments of the original sequence of people (covering entire sequence by segments is not necessary). People who are in the same segment will be in the same train carriage. The segments are selected in such way that if at least one person travels to the city xx , then all people who are going to city xx should be in the same railway carriage. This means that they can’t belong to different segments. Note, that all people who travel to the city xx , either go to it and in the same railway carriage, or do not go anywhere at all.

Comfort of a train trip with people on segment from position ll to position rr is equal to XOR of all distinct codes of cities for people on the segment from position ll to position rr . XOR operation also known as exclusive OR.

Total comfort of a train trip is equal to sum of comfort for each segment.

Help Vladik to know maximal possible total comfort.

输入格式

First line contains single integer nn ( 1<=n<=50001<=n<=5000 ) — number of people.

Second line contains nn space-separated integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 0<=ai<=50000<=a_{i}<=5000 ), where aia_{i} denotes code of the city to which ii -th person is going.

输出格式

The output should contain a single integer — maximal possible total comfort.

输入输出样例

  • 输入#1

    6
    4 4 2 5 2 3
    

    输出#1

    14
    
  • 输入#2

    9
    5 1 3 1 5 2 4 2 5
    

    输出#2

    9
    

说明/提示

In the first test case best partition into segments is: [4,4][4,4] [2,5,2][2,5,2] [3][3] , answer is calculated as follows: 4+(24+(2 xorxor 5)+3=4+7+3=145)+3=4+7+3=14

In the second test case best partition into segments is: 55 11 [3][3] 11 55 [2,4,2][2,4,2] 55 , answer calculated as follows: 3+(23+(2 xorxor 4)=3+6=94)=3+6=9 .

首页