-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay39.java
More file actions
58 lines (44 loc) · 1.5 KB
/
Day39.java
File metadata and controls
58 lines (44 loc) · 1.5 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
import java.util.*;
public class Day39 {
static int findMaxXOR(int[] arr, int Xi, int Ai) {
int max = -1;
for (int num : arr) {
if (num <= Ai) {
max = Math.max(max, Xi ^ num);
}
}
return max;
}
static int[] bitwiseXORQueries(int[] arr, int[][] queries) {
int[] result = new int[queries.length];
for (int i = 0; i < queries.length; i++) {
int Xi = queries[i][0];
int Ai = queries[i][1];
result[i] = findMaxXOR(arr, Xi, Ai);
}
return result;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while (T-- > 0) {
int N = scanner.nextInt();
int M = scanner.nextInt();
int[] arr = new int[N];
for (int i = 0; i < N; i++) {
arr[i] = scanner.nextInt();
}
int[][] queries = new int[M][2];
for (int i = 0; i < M; i++) {
queries[i][0] = scanner.nextInt();
queries[i][1] = scanner.nextInt();
}
int[] result = bitwiseXORQueries(arr, queries);
for (int res : result) {
System.out.print(res + " ");
}
System.out.println();
}
scanner.close();
}
}