51Nod--2063--二分

输入一个整数n和n个整数,保证这n个整数已经按照从小到大进行排序。
然后输入一个整数q(q <= 100000)代表q次查询。接下来q行,每行含有一个整数m,代表一次查询。对于每次查询,使用二分查找判断m是否在之前输入的n个整数中出现过。如果出现,输出一行"Yes",否则输出"No"。

Input

第一行:一个整数n(n <= 100000)。 接下来n行,每行一个整数ai(1 <= ai <= 10^9)。 接下来一行,一个整数q。 接下来q行,每行输入一个整数x(1 <= x <= 10^9)。

Output

q行字符串,每行为"Yes"或"No"。

Sample Input
5
1
3
4
5
7
3
4
5
0
Sample Output
Yes
Yes
No
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
const int maxa=1e5+10;
int n,m,ans; 
int a[maxa];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	scanf("%d",&m);
	for(int i=0;i<m;i++){
		scanf("%d",&ans);
		if(binary_search(a,a+n,ans)) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/queque_heiya/article/details/106185395
今日推荐