-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1920.java
More file actions
59 lines (49 loc) · 1.38 KB
/
1920.java
File metadata and controls
59 lines (49 loc) · 1.38 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
59
import java.io.*;
import java.util.*;
public class Main {
public static int N;
public static int M;
public static int[] a;
public static int[] m;
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
a = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i = 0;i<N;i++){
a[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(a);
M = Integer.parseInt(br.readLine());
m = new int[M];
st = new StringTokenizer(br.readLine());
for(int i = 0;i<M;i++){
m[i] = Integer.parseInt(st.nextToken());
}
for(int i = 0;i<M;i++){
if(biSearch(m[i]) >=0){
System.out.println("1");
}
else{
System.out.println("0");
}
}
}
public static int biSearch(int num){
int first = 0;
int last = a.length - 1;
while(first<=last){
int mid = (first + last) /2;
if (num < a[mid]){
last = mid -1;
}
else if(num> a[mid]){
first = mid + 1;
}
else{
return mid;
}
}
return -1;
}
}