class
trie:
def
__init__(
self
, value:
int
=
0
)
-
>
None
:
self
.value
=
value
self
.child
=
[
None
]
*
2
def
get()
-
> trie:
root
=
trie()
root.value
=
0
root.child[
0
]
=
None
root.child[
1
]
=
None
return
root
def
max_xor(root: trie, key:
int
)
-
>
int
:
temp
=
root
for
i
in
range
(
31
,
-
1
,
-
1
):
current_bit
=
(key & (
1
<< i))
if
(current_bit >
0
):
current_bit
=
1
if
(temp.child[
1
-
current_bit] !
=
None
):
temp
=
temp.child[
1
-
current_bit]
else
:
temp
=
temp.child[current_bit]
return
(key ^ temp.value)
def
insert(root: trie, key:
int
)
-
>
None
:
temp
=
root
for
i
in
range
(
31
,
-
1
,
-
1
):
current_bit
=
key & (
1
<< i)
if
(current_bit >
0
):
current_bit
=
1
if
(temp.child[current_bit]
=
=
None
):
temp.child[current_bit]
=
get()
temp
=
temp.child[current_bit]
temp.value
=
key
if
__name__
=
=
"__main__"
:
A
=
[
7
,
3
,
9
,
12
]
B
=
[
1
,
3
,
5
,
2
]
N
=
len
(A)
root
=
get()
for
i
in
range
(N):
insert(root, B[i])
for
i
in
range
(N):
print
(max_xor(root, A[i]))