Advertisement
LEGEND2004

Binary search - 1

Feb 26th, 2023
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n , q , k;
  6.     cin >> n >> q;
  7.     int a[n + 2];
  8.     for(int i = 0; i < n; i++){
  9.         cin >> a[i];
  10.     }
  11.     sort(a , a + n);
  12.     while(q--){
  13.         cin >> k;
  14.         int ans = upper_bound(a , a + n , k) - lower_bound(a , a + n , k);
  15.         cout << ans << endl;
  16.     }
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement