-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHAILXOR.cpp
54 lines (53 loc) · 868 Bytes
/
HAILXOR.cpp
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
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long int
#define xp(p) pow(2,p)
#define l(x) log2(x)
using namespace std;
int main(void)
{
IOS;
int t;
cin>>t;
while(t--)
{
ll n,x;
cin>>n>>x;
ll a[n];
for(ll i = 0;i<n;i++)
cin>>a[i];
ll k,i=0;
for(k = x ; k>0 && i<n-1;k--)
{
int flag = 0;
ll p,r;
p = l(a[i]);
r = xp(p);
a[i] = a[i] ^ r;
for(ll j = i+1 ;j<n;j++)
{
if(a[j] ^ r < a[j])
{
a[j] = a[j] ^ r;
flag = 1;
break;
}
}
if(flag == 0) a[n-1] = a[n-1] ^ r;
while(a[i]<0) i++;
ll z;
z = k+1;
if(z>0)
{
if(n<3 && z%2==0)
{
a[n-1] = a[n-1] ^1;
a[n-2] = a[n-2] ^1;
}
}
}
for(ll c = 0;c<n;c++) cout<<a[c]<<" ";
cout<<"\n";
}
return 0;
}