Advertisement
maycod23

Untitled

Feb 20th, 2022
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. # include   <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5. typedef pair<ll, ll> pl;
  6.  
  7. typedef vector<ll> vl;
  8.  
  9. ///these are some Macros which you can use in your code too
  10.  
  11. # define    fast                ios_base::sync_with_stdio(false);cin.tie(NULL);
  12. # define    endl                '\n'
  13. # define    INF                 9e18
  14. # define    PI                  3.14159265358979323846
  15. # define    lb                  lower_bound
  16. # define    ub                  upper_bound
  17. # define    mp                  make_pair
  18. # define    pb                  push_back
  19. # define    fi                  first
  20. # define    se                  second
  21. # define    all(a)              a.begin(), a.end()
  22. int main()
  23. {
  24.     fast;
  25.     ll t = 1;
  26.     // cin >> t;
  27.     while (t--)
  28.     {
  29.         ll n, m, i, j, count = 0;
  30.         cin >> n >> m;
  31.         vl a(n), b(m);
  32.         for (i = 0; i < n; i++) cin >> a[i];
  33.         for (i = 0; i < m; i++) cin >> b[i];
  34.         sort(all(a));//sorted vector for binary search
  35.         for (i = 0; i < m; i++)
  36.         {
  37.             //auto keyword
  38.             auto it = upper_bound(a.begin(), a.end(), b[i]);
  39.             cout << it - a.begin() << " ";
  40.         }
  41.         //example
  42.         //indexes 0 1 2 3 4 5 6
  43.         //vector  1 2 3 3 4 4 5
  44.  
  45.         // ll x=4 ( say any element of vector b)
  46.         //how many elemnts are there in vector which are less than or
  47.         //equal to 4
  48.         // ll ans=6 (founded upper bound of 4 in vector a)
  49.  
  50.         //ll x=3
  51.         //upper bound->4th index
  52.         //lower bound->2nd index
  53.         cout << endl;
  54.     }
  55.     return 0;
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement