Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- string binary(int start, int end, vector<int> a, int search) {
- if ((start == end && a[start] != search) || start > end) {
- return "NO";
- } else {
- int ser = (start + end) / 2;
- if (a[ser] > search) {
- return binary(start, ser - 1, a, search);
- } else if (a[ser] < search) {
- return binary(ser + 1, end, a, search);
- } else {
- return "YES";
- }
- }
- }
- int main() {
- int n, k, t;
- cin >> n;
- cin >> k;
- vector<int> a(n);
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- }
- for (int i = 0; i < k; i++) {
- cin >> t;
- cout << binary(0, n - 1, a, t) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement