fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pb push_back
  5. #define R return
  6. #define fi first
  7. #define se second
  8. #define yes cout<<"YES\n";
  9. #define no cout<<"NO\n";
  10. const int N=2e5+7;
  11. ll T=1;
  12. void solve()
  13. {
  14. ll n,q;
  15. cin >> n >> q;
  16. int a[n+2];
  17. for(int i=1;i<=n;i++){
  18. cin >> a[i];
  19. }
  20. for(int i=0;i<q;i++){
  21. int x;
  22. cin >> x;
  23. cout << upper_bound(a+1,a+n+1,x) - a - 1<< endl ;
  24. }
  25. }
  26. int main()
  27. {
  28. ios::sync_with_stdio(NULL);
  29. cin.tie(0);
  30. cout.tie(0);
  31. //cin>>T;
  32. while(T--)
  33. solve();
  34. R 0;
  35. }
Success #stdin #stdout 0s 5320KB
stdin
5 5
3 3 5 8 9
2 4 8 1 10
stdout
0
2
4
0
5