#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
bool b_search(const vector<int> &a, int x) {
int left = 0, right = a.size() - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (a[mid] == x) return true;
if (a[mid] < x) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return false;
}
int main() {
int n;
while (scanf(" %d", &n) != EOF) {
vector<int> a;
for (int i = 0; i < n; ++i) {
int temp;
scanf("%d", &temp);
a.push_back(temp);
}
sort(a.begin(),a.end());
int m;
scanf("%d", &m);
for (int j = 0; j < m; ++j) {
int temp;
scanf("%d", &temp);
if (b_search(a, temp)) printf("YES\n");
else printf("NO\n");
}
}
return 0;
}
问题 C: 查找
最新推荐文章于 2024-08-15 10:12:07 发布