-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntprob5.java
More file actions
50 lines (48 loc) · 1.3 KB
/
Copy pathIntprob5.java
File metadata and controls
50 lines (48 loc) · 1.3 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
import java.util.*;
public class Intprob5{
static int [][]trie=new int[300000][2];
static int nodecount=0;
static void insert(int n){
int curr=0;
for(int i=29;i>=0;i--){
int bit=(n>>i)&1;
if(trie[curr][bit]==0){
trie[nodecount][0]=0;
trie[nodecount][1]=0;
trie[curr][bit]=nodecount++;
}
curr=trie[curr][bit];
}
}
static int query(int n){
int curr=0;
int ans=0;
for(int i=29;i>=0;i--){
int bit=(n>>i)&1;
int opp=1-bit;
if(trie[curr][opp]!=0){
ans|=(1<<i);
curr=trie[curr][opp];
}else if (trie[curr][bit]!=0)curr=trie[curr][bit];
else break;
}
return ans;
}
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int maz=0;
int n=sc.nextInt();
trie[0][0]=0;
trie[0][1]=0;
nodecount=1;
for(int i=0;i<n;i++){
int a=sc.nextInt();
if(i>0) maz=Math.max(maz,query(a));
insert(a);
}
System.out.println(maz);
}
}
}