题目:\
模板题,无背景
输入一个整数n和n个整数,保证这n个整数已经按照从小到大进行排序。 然后输入一个整数q(q <= 100000)代表q次查询。接下来q行,每行含有一个整数m,代表一次查询。对于每次查询,使用二分查找判断m是否在之前输入的n个整数中出现过。
如果出现,输出一行"Yes",否则输出"No"。
第一行:一个整数n(n <= 100000)。 接下来n行,每行一个整数ai(1 <= ai <= 10^9)。 接下来一行,一个整数q。 接下来q行,每行输入一个整数x(1 <= x <= 10^9)。
q行字符串,每行为"Yes"或"No"。
5
1
3
4
5
7
3
4
5
0
Yes
Yes
No
代码:\
#include<bits/stdc++.h>
using namespace std;
#define int long long
int father[100005];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>father[i];
}
sort(father+1,father+1+n);
int q;
cin>>q;
for(int i=1;i<=q;i++)
{
int x;
cin>>x;
if(*(lower_bound(father+1,father+1+n,x))==x)
{
//cout<<(lower_bound(father+1,father+1+n,x)-father)<<" ";
//puts("Yes");
cout<<"Yes\n";
}
else
{
//cout<<*(lower_bound(father+1,father+1+n,x))<<" ";
//puts("No");
cout<<"No\n";
}
}
return 0;
}
0pts,求助