Problems
Ternary search in array
Ternary search in array
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 $n$ integers is given. You must answer $q$ queries: whether the given number $x$ is in the array.
\InputFile
First line contains two numbers $n$ and $q~(n, q \le 10^6)$. Second line contains $n$ integers sorted in increasing order. Each of the next $q$ lines contains value of $x$. The numbers in array do not exceed $10^9$ by absolute value.
\OutputFile
For each value of $x$ print on a separate line "\textbf{YES}" if $x$ is present in array and "\textbf{NO}" otherwise.
Input example #1
6 3 2 4 4 8 11 14 10 4 2
Output example #1
NO YES YES
Input example #2
8 4 -8 -8 -1 1 3 4 6 8 4 10 -4 -8
Output example #2
YES NO NO YES