B. AGAGA XOOORRR Codeforces Round 717 (Div. 2)

Baby Ehab is known for his love for a certain operation. He has an array a� of length n�, and he decided to keep doing the following operation on it:

  • he picks 22 adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR. Note that the length of the array decreases by one.

Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least 22 elements remaining.

Input

The first line contains an integer t� (1≤t≤151≤�≤15) — the number of test cases you need to solve.

The first line of each test case contains an integers n� (2≤n≤20002≤�≤2000) — the number of elements in the array a�.

The second line contains n� space-separated integers a1�1, a2�2, ……, an�� (0≤ai<2300≤��<230) — the elements of the array a�.

Output

If Baby Ehab can make all elements equal while leaving at least 22 elements standing, print "YES". Otherwise, print "NO".

Example

input

Copy

2
3
0 2 2
4
2 3 1 10

output

Copy

YES
NO

Note

In the first sample, he can remove the first 22 elements, 00 and 22, and replace them by 0⊕2=20⊕2=2. The array will be [2,2][2,2], so all the elements are equal.

In the second sample, there's no way to make all the elements equal.

题目大意:

相邻的值异或(^)一下,然后把两个值取出,在当前位置放入异或结果,直到把整个数组异或到都是同一个数值。

问最后能不能留下至少两个数?

思路:

先整体异或一遍,得到最后异或的值。

1、值为0(只有两个相同的数异或才能得到0),说明肯定能异或出两个一样的值。

2、再模拟跑一边,看中途异或出与整体异或结果相同的值有几个,如果个数>=2就可行。

方法:

跑单for模拟。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"

const ll N = 2e3+7; 
ll n,m;
ll v[N];

void solve(){
	cin >> n;
	ll sum=0,cnt=0,op=0;//最后的异或值,等于sum的值有几个,异或相邻值的结果 
	for(ll i = 0 ; i < n ; i ++)
		cin >> v[i],
		sum^=v[i];
	if(!sum){//最后异或值为0 
		cout << "YES" << endl;
		return;
	}
	for(ll i = 0 ; i < n ; i ++){//看异或值等于sum的有几个 
		op^=v[i];
		if(op == sum)
			cnt ++, 
			op = 0;//重置
	}
	cnt >= 2 ? cout << "YES" << endl : cout << "NO" << endl;
	return;
}

int main(){
	ll t=1;cin >> t;
	while(t --)solve();
	return 0;
}
  • 13
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值