fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pb push_back
  5. #define yes cout<<"YES\n";
  6. #define no cout<<"NO\n";
  7. const int N=3e5+7;
  8. ll T = 1, a[N], b[N];
  9. void solve()
  10. {
  11. int n, m;
  12.  
  13. cin >> n >> m;
  14.  
  15. for(int i = 1; i <= n; i++)
  16. cin >> a[i];
  17.  
  18. for(int i = 1; i <= m; i++)
  19. cin >> b[i];
  20.  
  21. int l = 1;
  22. for(int i = 1; i <= m; i++){
  23. while(l <= n && a[l] < b[i])
  24. l++;
  25. cout << l - 1 << ' ';
  26. }
  27. }
  28. int main()
  29. {
  30. ios::sync_with_stdio(NULL);
  31. cin.tie(0);
  32. cout.tie(0);
  33.  
  34. // freopen("","r", stdin);
  35. // freopen("","w", stdout);
  36. // cin>>T;
  37. while(T--)
  38. solve();
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.01s 5660KB
stdin
6 7
1 6 9 13 18 18
2 3 8 13 15 21 25
stdout
1 1 2 3 4 6 6