Advertisement
zhukov000

Binary search example 1

Nov 15th, 2019
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. from bisect  import bisect_left, bisect_right
  2.  
  3. n, k = map(int, input().split())
  4. a = [int(x) for x in input().split()]
  5.  
  6. def binary_search(x, a):
  7.     left = 0
  8.     right = len(a)
  9.     while right - left > 1:
  10.         mid = (left + right) // 2
  11.         if a[mid] > x:
  12.             right = mid
  13.         else:
  14.             left = mid
  15.     return a[left] == x
  16.  
  17. for x in input().split():
  18.     x = int(x)
  19.     if bisect_left(a, x) != bisect_right(a, x):
  20.         print('YES')
  21.     else:
  22.         print('NO')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement