-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagagaxorr1500.cpp
More file actions
68 lines (64 loc) · 1.63 KB
/
agagaxorr1500.cpp
File metadata and controls
68 lines (64 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<string>
using namespace std;
typedef long long ll;
int main(){
int t;
cin >> t;
while(t--){
ll n;
cin >> n;
vector<ll> nums(n);
for(ll i = 0; i < n; i++){
cin >> nums[i];
}
ll totalXor = 0;
for(ll i = 0; i < n; i++){
totalXor ^= nums[i];
}
// a1 a2 a3 a4 a5
// XOR of 1^1 = 0
// XOR of 1^0 = 1
// x1 a3 a4 a5
// xor of entire array will be less than equal to max(arr[i]);
// 0010 -> a
// 0011 -> b
// 0001 -> c
// 1010 -> d
// a^b then c^d then (a^b)^(c^d)
// a^b then (a^b)^c then ((a^b)^c)^d
// basically bcz adjacent are allowed so leaving 1st rem ka xor
// or leaing last rem ka xor
// or first x ka xor and remaininh n - x or
// so for a b c d
// a (b^c^d)
// (a^b^c) d
// a^b and c^d
// so basically a then rem
// a^b then rem
// a^b^c then rem
// so what we can do is store prefix and suffix xor and if they equal return true
if(totalXor == 0){
cout << "YES" << endl;
continue;
}
ll prefixXor = 0, count = 0;
for(ll i = 0; i < n; i++){
prefixXor ^= nums[i];
if(prefixXor == totalXor){
count++;
prefixXor = 0;
}
}
if(count >= 2){
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}