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,q;
  17. cin >> n >> q;
  18.  
  19. vector<int>v(n);
  20. for(auto &x : v) cin >> x;
  21.  
  22. while(q--){
  23. int x;
  24. cin >> x;
  25.  
  26. int l = 0, r = n-1, ans = -1, mid;
  27.  
  28. while(l<=r){
  29. mid = (l+r)/2;
  30. if(v[mid] >= x){
  31. ans = mid;
  32. r = mid - 1;
  33. }
  34. else{
  35. l = mid + 1;
  36. }
  37. }
  38. if(ans == -1) cout << ans << '\n';
  39. else cout << ans+1 << '\n';
  40. }
  41. }
  42.  
  43.  
  44. signed main(){
  45. FastIO();
  46.  
  47. int t = 1;
  48. //cin >> t;
  49.  
  50. while (t--){
  51. solve();
  52. }
  53. return 0;
  54. }
Success #stdin #stdout 0s 5320KB
stdin
3 3
1 5 7
3
6
12
stdout
2
3
-1