fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<int>v={0, 0, 0, 1, 1, 1, 1};
  5.  
  6. int main() {
  7. int l = 0;
  8. int r = v.size()-1;
  9. int res = -1;
  10. while(l<=r){
  11. int mid = l + (r-l)/2;
  12. if(v[mid]==1){
  13. res = mid;
  14. r=mid-1;
  15. }else{
  16. l=mid+1;
  17. }
  18. }
  19. cout<<res<<endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
3