#include <stdio.h>
#include <stdlib.h>
int num[500001];
int compare(const void *a,const void *b) {
return *(int *)a-*(int *)b;
}
int binary(int target,int start,int end) {
while(start<=end) {
int mid=(start+end)/2;
if(num[mid]==target) return 1;
else if(num[mid]>target) end=mid-1;
else if(num[mid]<target) start=mid+1;
}
return 0;
}
int main() {
int n;
scanf("%d",&n);
for(int i=0; i<n; i++) {
scanf("%d",&num[i]);
}
qsort(num,n,sizeof(int),compare);
int m;
scanf("%d",&m);
while(m--) {
int target;
scanf("%d",&target);
printf("%d ",binary(target, 0, n-1));
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: