fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int a[100005];
  4. int main()
  5. {
  6. int n, k;
  7. cin >> n >> k;
  8.  
  9. for(int i = 1; i <= n; i++)
  10. cin >> a[i];
  11.  
  12. while(k--){
  13. int x;
  14. cin >> x;
  15.  
  16. int l = 1, r = n, ans = n + 1;
  17.  
  18. while(l <= r){
  19. int mid = (l + r) / 2;
  20.  
  21. if(a[mid] >= x){
  22. ans = mid;
  23. r = mid - 1;
  24. }
  25. else l = mid + 1;
  26. }
  27.  
  28. cout << ans << endl;
  29. }
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5264KB
stdin
5 5
3 3 5 8 9
2 4 8 1 10
stdout
1
3
4
1
6