【Codeforces 282E】Sausage Maximization 中文题意&题解&代码(C++)

本文介绍了如何解决Bitlandian文化中关于香肠最大化的数学问题,即如何切分香肠,使得两位顾客得到的香肠异或和最大。问题转化为寻找数组中一个前缀和后缀的最大异或值。通过使用字典树进行贪心策略,可以在O(n*50)的时间复杂度内找出解决方案。文章提供了具体的思路、样例测试及C++代码实现。
摘要由CSDN通过智能技术生成

E. Sausage Maximization

time limit per test2 seconds
memory limit per test256 megabytes


The Bitlandians are quite weird people. They have their own problems and their own solutions. They have their own thoughts and their own beliefs, they have their own values and their own merits. They have their own dishes and their own sausages!

In Bitland a sausage is an array of integers! A sausage’s deliciousness is equal to the bitwise excluding OR (the xor operation) of all integers in that sausage.

One day, when Mr. Bitkoch (the local cook) was going to close his BitRestaurant, BitHaval and BitAryo, the most famous citizens of Bitland, entered the restaurant and each ordered a sausage.

But Mr. Bitkoch had only one sausage left. So he decided to cut a prefix (several, may be zero, first array elements) of the sausage and give it to BitHaval and a postfix (several, may be zero, last array elements) of the sausage and give it to BitAryo. Note that one or both pieces of the sausage can be empty. Of course, the cut pieces mustn’t intersect (no array element can occur in both pieces).

The pleasure of BitHaval and BitAryo is equal to the bitwise XOR of their sausages’ deliciousness. An empty sausage’s deliciousness equals zero.

Find a way to cut a piece of sausage for BitHaval and BitAryo that maximizes the pleasure of these worthy citizens.


Input

The first line contains an integer n (1 ≤ n ≤ 105).

The next line contains n integers a1, a2, …, an (0 ≤ ai ≤ 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值