fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define int long long
  5. #define yes cout << "YES\n";
  6. #define no cout << "NO\n";
  7.  
  8.  
  9. void FastIO() {
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(nullptr);
  12. cout.tie(nullptr);
  13. }
  14.  
  15. void solve(){
  16. int n,m;
  17. cin >> n >> m;
  18.  
  19. vector<int>a(n),b(m);
  20. for(auto &x : a) cin >> x;
  21. for(auto &x : b) cin >> x;
  22.  
  23. sort(a.begin(), a.end());
  24.  
  25. for(auto&x : b){
  26. int l = 0, r = n-1, ans = n, mid;
  27.  
  28. while(l<=r){
  29. mid = (l+r)/2;
  30. if(a[mid] > x){
  31. ans = mid;
  32. r = mid - 1;
  33. }
  34. else{
  35. l = mid + 1;
  36. }
  37. }
  38. cout << ans << ' ';
  39. }
  40. }
  41.  
  42.  
  43. signed main(){
  44. FastIO();
  45.  
  46. int t = 1;
  47. //cin >> t;
  48.  
  49. while (t--){
  50. solve();
  51. }
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5320KB
stdin
5 5
1 2 1 2 5
3 1 4 1 5
stdout
4 2 4 2 5