Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define read(vec, n) for(int i = 0 ; i < n && cin >> vec[i] ; i++);
- #define print(v, template) copy(all(v), ostream_iterator <template> (cout, " "));
- #define read_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> nums[i][j]; j++);
- #define loop(a, b, c) for(int i = a ; i < (b); i += c)
- #define Ceil(n, m) ((n / m) + ( n % m ? 1 : 0))
- #define all(vec) vec.begin(),vec.end()
- #define rall(vec) vec.rbegin(),vec.rend()
- #define Pair pair <int,int>
- #define ll long long
- #define ull unsigned long long
- #define Mod 1'000'000'007
- #define INF 2000'000'000
- #define PI 3.14159
- void Code_Crush(){
- ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- vector <int> nums(1000);
- bool binary_search (int l, int r, int num){
- while(l <= r){
- int mid = l + (r - l) / 2;
- if(nums[mid] == num) return true;
- (nums[mid] > num ? r = mid - 1 : l = mid + 1);
- }
- return false;
- }
- int main(){
- Code_Crush();
- int n, q; cin >> n >> q;
- nums.resize(n);
- read(nums, n);
- while(q--){
- int item; cin >> item;
- cout << (binary_search(0, n, item) ? "YES\n" : "NO\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement