Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
547 B
1
Indexable
Never
#include<stdio.h>

int n,q;
int ary[1000000];

int binary_search(int find){
	int l=0,r=n-1;
	int mid=(l+r)/2;
	int count=0;
	int ans=-1;
	while(l<=r){count++;
		mid=(l+r)/2;
		if(ary[mid]==find){
			ans=1;
			break;
		}
		else if(ary[mid]>find){
			r=mid-1;
		}
		else{
			l=mid+1;
		}
	}
	return ans;
}

int main(){
	scanf("%d%d",&n,&q);
	for(int i=0;i<n;i++){
		scanf("%d",&ary[i]);
	}
	for(int i=0;i<q;i++){
		int tmp;
		scanf("%d",&tmp);
		int ans=binary_search(tmp);
		if(ans==1){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}

	}

}