-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ10816.java
More file actions
74 lines (63 loc) · 1.86 KB
/
Copy pathJ10816.java
File metadata and controls
74 lines (63 loc) · 1.86 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package TIL;
import java.io.*;
import java.util.*;
public class J10816 {
public static void main(String[] args) throws IOException {
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(buffer.readLine());
int[] card = new int[n];
String[] input = buffer.readLine().split(" ");
for(int i = 0; i<n; i++ ) card[i] = Integer.parseInt(input[i]);
int m = Integer.parseInt(buffer.readLine());
int[] cntCard = new int[m];
input = buffer.readLine().split(" ");
for(int i = 0; i<m; i++ ) cntCard[i] = Integer.parseInt(input[i]);
Arrays.sort(card);
for(int i = 0; i< m; i++){
boolean isHas = false;
int start = 0;
int end = n-1;
int key = cntCard[i];
while(start <= end){
int mid = (start + end)/2;
if(card[mid]>key){
end = mid-1;
} else if (card[mid]<key) {
start = mid+1;
}
else {
isHas = true;
break;
}
}
if(isHas)System.out.print("1"+ " ");
else System.out.print("0"+ " ");
}
}
public static int low(int[] arr, int key){
int l = 0;
int h = arr.length;
while(l<h){
int mid =(l + h)/2;
if(key<arr[mid]){
h = mid;
}else {
l = mid +1;
}
}
return l;
}
public static int high(int[] arr, int key){
int l = 0;
int h = arr.length;
while(l<h){
int mid = (l+h)/2;
if(key <= arr[mid]){
h = mid;
}else{
l = mid +1;
}
}
return l;
}
}