Pagini recente » Cod sursa (job #846868) | Cod sursa (job #1358538) | Cod sursa (job #1867159) | Cod sursa (job #291726) | Cod sursa (job #1651252)
#include<fstream>
using namespace std;
ifstream cin("cautbin.in");
ofstream cout("cautbin.out");
int n,v[100001],m,x,y,st,dr,p;
int main(){
cin>>n;
for(int i=1;i<=n;i++)
cin>>v[i];
cin>>m;
while(m--){
cin>>x;
if(x==0){cin>>y;
st=1;
dr=n;
while(st<=dr){
p=(st+dr)/2;
if(v[p]<=y)st=p+1;
else dr=p-1;
}
p=(st+dr)/2;
if(v[p]>y)p--;
if(v[p]==y)cout<<p<<"\n";
else cout<<"-1\n";
}
if(x==1){cin>>y;
st=1;
dr=n;
while(st<dr){
p=(st+dr)/2;
if(v[p]<=y)st=p+1;
else dr=p-1;
}
p=(st+dr)/2;
if(v[p]>y)p--;
if(v[p]<=y)cout<<p<<"\n";
}
if(x==2){cin>>y;
st=1;
dr=n;
while(st<dr){
p=st+dr;
p/=2;
if(v[p]<y)st=p+1;
else dr=p-1;
}
p=st+dr;
p/=2;
if(v[p]<y)p++;
cout<<p<<"\n";
}
}
}