fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. vector<int>searchRange(const vector<int> &A, int B) {
  4. int size = A.size();
  5. int low =0, high = size-1;
  6. int mid;
  7. while(low<=high) {
  8.  
  9. mid = low + (high-low)/2;
  10. if(A[mid]<B) {
  11. low = mid+1;
  12. }
  13. else high = mid - 1;
  14.  
  15. }
  16. int positionOne = low;
  17. cout<<positionOne<<endl;
  18.  
  19. low = 0, high = size - 1;
  20.  
  21. while(low<=high) {
  22.  
  23. mid = low + (high-low)/2;
  24. if(A[mid]<=B) {
  25. low = mid+1;
  26. }
  27. else high = mid - 1;
  28.  
  29. }
  30.  
  31. int positionTwo = low;
  32.  
  33. if(A[positionOne] != B) return {-1,-1};
  34. return {A[positionOne],A[positionTwo-1]};
  35.  
  36. }
  37.  
  38. int main() {
  39. // your code goes here
  40. vector<int>ans = searchRange({1},1);
  41. cout<<ans[0]<< " "<<ans[1];
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
0
1 1