Skip to content

Instantly share code, notes, and snippets.

@abhishek2x
Created December 19, 2020 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhishek2x/2435d80884fd22f7aeb7c1e43346cbc1 to your computer and use it in GitHub Desktop.
Save abhishek2x/2435d80884fd22f7aeb7c1e43346cbc1 to your computer and use it in GitHub Desktop.
Searching in Bitonic Infinite Array.
/*!
* Copyright (c) 2020 Abhishek Srivastava
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
ios :: sync_with_stdio(false);
cin.tie(0);
vector<int> bInf = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int l=0, h=1, mid;
while(bInf[h] < 1){
h *= 2;
}
int firstOccr;
while(l <= h) {
mid = l+(h-l)/2;
if(bInf[mid] == 1){
firstOccr = mid;
h = mid-1;
}
else if (bInf[mid] < 1){
l = mid + 1;
} else {
h = mid-1;
}
}
cout << firstOccr;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment