C. Vampiric Powers, anyone?

文章描述了一个关于DIO和StardustCrusaders的战斗策略问题。DIO可以使用他的能力召唤具有特定力量的Stand用户,力量值通过bitwiseXOR运算确定。Crusaders试图预测最大可能的力量值。给定初始用户力量,问题在于找出所有可能召唤方式中的最大力量值。
摘要由CSDN通过智能技术生成

DIO knows that the Stardust Crusaders have determined his location and will be coming to fight him. To foil their plans he decides to send out some Stand users to fight them. Initially, he summoned n Stand users with him, the i-th one having a strength of ai. Using his vampiric powers, he can do the following as many times as he wishes:

  • Let the current number of Stand users be m.
  • DIO chooses an index i (1≤i≤m).
  • Then he summons a new Stand user, with index m+1 and strength given by:

    am+1=ai⊕ai+1⊕…⊕am,

    where the operator ⊕⊕ denotes the bitwise XOR operation.

  • Now, the number of Stand users becomes m+1.

Unfortunately for DIO, by using Hermit Purple's divination powers, the Crusaders know that he is plotting this, and they also know the strengths of the original Stand users. Help the Crusaders find the maximum possible strength of a Stand user among all possible ways that DIO can summon.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤10000). The description of the test cases follows.

The first line of each test case contains a single integer n (1≤n≤10Q^5)  – the number of Stand users initially summoned.

The second line of each test case contains n integers a1,a2,…,an (0≤ai<2^8)  – the strength of each Stand user.

It is guaranteed that the sum of n over all test cases does not exceed 105105.

Output

For each test case, output a single integer, maximum strength of a Stand user among all possible ways that DIO can summon.

Example

input

Copy

 

3

4

0 2 5 1

3

1 2 3

5

8 2 4 12 1

output

Copy

7
3
14

Note

In the first test case, one of the ways to add new Stand users is as follows:

  • Choose i=n. Now, a becomes [0,2,5,1,1].
  • Choose i=1. Now, a becomes [0,2,5,1,1,7]. 7 is the maximum strength of a Stand user DIO can summon.

In the second test case, DIO does not need to add more Stand users because 3 is the maximum strength of a Stand user DIO can summon.

本题用前缀异或和;

由于ai<=256,so 可用set存 前缀和a[i],

then 由于a[l-1]^a[r]为l到r的一段异或,so 双重for循环找最大值即可。

#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
#define  endl '\n'
#define lowbit(x) ((x)&-(x))
const int mod=1e9+7;
typedef long long ll;
ll ans=0,n1,m1;
ll t,s1,s2,s3,s4,max1=0,min1=100000000,sum=0,n,m,i,j,k,l,r;
ll u,v,w;
inline int read() {
	bool sym=0;
	int res=0;
	char ch=getchar();
	while(!isdigit(ch))sym |=(ch =='-'),ch=getchar();
	while(isdigit(ch)) res =(res<<3)+(res<<1)+(ch^48),ch=getchar();
	return sym ? -res : res;
}
void print(int x) {
	if(!x)return;
	print(x/10);
	putchar(x%10+'0');
}
int isPrime(int n)
{	
	float n_sqrt;
    if(n==1) return 0;
	if(n==2 || n==3) return 1;
	if(n%6!=1 && n%6!=5) return 0;
	n_sqrt=floor(sqrt((float)n));
	for(int i=5;i<=n_sqrt;i+=6)
	{
	    if(n%(i)==0 | n%(i+2)==0) return 0;
	}
        return 1;  
}
ll a[100086];
set<ll>st;
int main() {


	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
cin>>t;
while(t--){
	cin>>n;
	st.clear();
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	ans=0;
	for(i=1;i<=n;i++)
	a[i]^=a[i-1];//前缀异或和 
	for(i=0;i<=n;i++)
	st.insert(a[i]);
	for(auto it=st.begin();it!=st.end();it++){
		
		for(auto ii=st.begin();ii!=st.end();ii++){
			
		ans=max(ans,*ii^*it);	
			
		}
	}
	cout<<ans<<endl;
}
	return 0;
}

//mio lover

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值