Ternary search in array#10866

Ternary search in array

5 Sekunden
128 Megabyte
Sehr leicht

Ternary search is a divide and conquer algorithm that can be used to find an element in an array. It is similar to binary search but in this algorithm, we divide the given array into three equal parts and determine which has the key (searched element).

Sorted array of integers is given. You must answer queries: whether the given number is in the array.

Eingabe

First line contains two numbers and q~(n, q \le 10^6). Second line contains integers sorted in increasing order. Each of the next lines contains value of . The numbers in array do not exceed 10^9 by absolute value.

Ausgabe

For each value of print on a separate line "YES" if is present in array and "NO" otherwise.

Beispiele

Beispiel 1

Loading
Loading

Beispiel 2

Loading
Loading