Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<ll, ll> pl;
- typedef vector<ll> vl;
- ///these are some Macros which you can use in your code too
- # define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
- # define endl '\n'
- # define INF 9e18
- # define PI 3.14159265358979323846
- # define lb lower_bound
- # define ub upper_bound
- # define mp make_pair
- # define pb push_back
- # define fi first
- # define se second
- # define all(a) a.begin(), a.end()
- int main()
- {
- fast;
- ll t = 1;
- // cin >> t;
- while (t--)
- {
- ll n, m, i, j, count = 0;
- cin >> n >> m;
- vl a(n), b(m);
- for (i = 0; i < n; i++) cin >> a[i];
- for (i = 0; i < m; i++) cin >> b[i];
- sort(all(a));//sorted vector for binary search
- for (i = 0; i < m; i++)
- {
- //auto keyword
- auto it = upper_bound(a.begin(), a.end(), b[i]);
- cout << it - a.begin() << " ";
- }
- //example
- //indexes 0 1 2 3 4 5 6
- //vector 1 2 3 3 4 4 5
- // ll x=4 ( say any element of vector b)
- //how many elemnts are there in vector which are less than or
- //equal to 4
- // ll ans=6 (founded upper bound of 4 in vector a)
- //ll x=3
- //upper bound->4th index
- //lower bound->2nd index
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement