#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000001 ; // Define max array size
int n, a[ MAXN] , q;
// Binary search function to check if target exists in sorted array
bool binary_search( int a[ ] , int sz, int target) {
int low = 0 , high = sz - 1 ;
while ( low <= high) {
int tg = ( low + high) / 2 ; // Compute middle index
if ( a[ tg] == target) return true ; // Target found
if ( target < a[ tg] ) high = tg - 1 ; // Search left half
else low = tg + 1 ; // Search right half
}
return false ; // Target not found
}
int main( ) {
// Read size of the array
cin >> n;
for ( int i = 0 ; i < n; ++ i) cin >> a[ i] ;
// Sorting the array to enable binary search
sort( a, a + n) ;
// Read number of queries
cin >> q;
while ( q-- ) {
int x;
cin >> x;
// Check if x exists in the array using binary search
if ( binary_search( a, n, x) )
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0 ;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTUFYTiA9IDEwMDAwMDE7IC8vIERlZmluZSBtYXggYXJyYXkgc2l6ZQoKaW50IG4sIGFbTUFYTl0sIHE7CgovLyBCaW5hcnkgc2VhcmNoIGZ1bmN0aW9uIHRvIGNoZWNrIGlmIHRhcmdldCBleGlzdHMgaW4gc29ydGVkIGFycmF5CmJvb2wgYmluYXJ5X3NlYXJjaChpbnQgYVtdLCBpbnQgc3osIGludCB0YXJnZXQpIHsKICAgIGludCBsb3cgPSAwLCBoaWdoID0gc3ogLSAxOwogICAgd2hpbGUgKGxvdyA8PSBoaWdoKSB7CiAgICAgICAgaW50IHRnID0gKGxvdyArIGhpZ2gpIC8gMjsgLy8gQ29tcHV0ZSBtaWRkbGUgaW5kZXgKICAgICAgICBpZiAoYVt0Z10gPT0gdGFyZ2V0KSByZXR1cm4gdHJ1ZTsgLy8gVGFyZ2V0IGZvdW5kCiAgICAgICAgaWYgKHRhcmdldCA8IGFbdGddKSBoaWdoID0gdGcgLSAxOyAvLyBTZWFyY2ggbGVmdCBoYWxmCi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