File tree Expand file tree Collapse file tree 1 file changed +113
-0
lines changed
Expand file tree Collapse file tree 1 file changed +113
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+
3+ import java.util.* ;
4+ import java.io.* ;
5+
6+ class Node {
7+ int d;
8+ Node l, r;
9+ Node (int d ){this . d = d;}
10+ }
11+
12+ class Trie {
13+ Node root;
14+ Trie (){root = new Node (31 );}
15+ void insert (int x ) {
16+ Node now = root;
17+ for (int i= 30 ;i>= 0 ;i-- ) {
18+ int bit = x & (1 << i);
19+ x -= bit;
20+ if (bit == 0 ) {
21+ if (now. l == null ) now. l = new Node (i);
22+ now = now. l;
23+ }
24+ else {
25+ if (now. r == null ) now. r = new Node (i);
26+ now = now. r;
27+ }
28+ }
29+ }
30+ // x 와 xor했을 때 가장 큰 값 찾기
31+ int find (int x ) {
32+ Node now = root;
33+ int res = 0 ;
34+ for (int i= 30 ;i>= 0 ;i-- ) {
35+ int bit = x & (1 << i);
36+ if (bit != 0 ) {
37+ if (now. l == null ) now = now. r;
38+ else {
39+ res += (1 << i);
40+ now = now. l;
41+ }
42+ }
43+ else {
44+ if (now. r == null ) now = now. l;
45+ else {
46+ res += (1 << i);
47+ now = now. r;
48+ }
49+ }
50+ }
51+ return res;
52+ }
53+ }
54+
55+ class Main {
56+
57+ // IO field
58+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
59+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
60+ static StringTokenizer st;
61+
62+ static void nextLine () throws Exception {st = new StringTokenizer (br .readLine ());}
63+ static int nextInt() {return Integer . parseInt(st. nextToken());}
64+ static long nextLong() {return Long . parseLong(st. nextToken());}
65+ static void bwEnd() throws Exception {bw. flush();bw. close();}
66+
67+ // Additional field
68+ static Trie trie;
69+ static int T , N ;
70+ static int [] S ;
71+
72+
73+ public static void main(String [] args) throws Exception {
74+
75+ ready();
76+ // solve();
77+
78+ bwEnd();
79+ }
80+
81+ static void ready() throws Exception {
82+
83+ T = Integer . parseInt(br. readLine());
84+ while (T -- > 0 ) {
85+ trie = new Trie ();
86+
87+ N = Integer . parseInt(br. readLine());
88+ S = new int [N + 1 ];
89+
90+ nextLine();
91+ for (int i= 1 ;i<= N ;i++ ) {
92+ S [i] = nextInt();
93+ S [i] ^ = S [i- 1 ];
94+ }
95+ solve();
96+ }
97+
98+ }
99+
100+ static void solve() throws Exception {
101+
102+ for (int i= 1 ;i<= N ;i++ ) trie. insert(S [i]);
103+
104+ int ans = 0 ;
105+ for (int i= 0 ;i< N ;i++ ) ans = Math . max(ans, trie. find(S [i]));
106+ bw. write(ans+ " \n " );
107+
108+ }
109+
110+
111+ }
112+
113+ ```
You can’t perform that action at this time.
0 commit comments