Advertisement
Andoroid

C

Dec 9th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n,k;
  6. int a[100000];
  7. int b[100000];
  8.  
  9. int binarySearch(int l, int r, int x)
  10. {
  11.     if (r >= l) {
  12.         int mid = l + (r - l) / 2;
  13.  
  14.         if (a[mid] == x)
  15.             return mid;
  16.  
  17.         if (a[mid] > x)
  18.             return binarySearch(l, mid - 1, x);
  19.  
  20.         return binarySearch(mid + 1, r, x);
  21.     }
  22.     return -1;
  23. }
  24.  
  25. int main() {
  26.     cin >> n >> k;
  27.     for(int i=0;i<n;i++) cin >> a[i];
  28.     for(int i=0;i<k;i++) cin >> b[i];
  29.     for(int i=0;i<k;i++)
  30.         cout << (binarySearch(0,n-1,b[i]) != -1? "YES" : "NO") << "\n";
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement