Pagini recente » Cod sursa (job #657420) | Cod sursa (job #1875779) | Cod sursa (job #2802) | Cod sursa (job #2319641) | Cod sursa (job #2343455)
#include<fstream>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int n, i, j, v[100010], t, st, p, x, y;
int main(){
fin>>n;
for(i=1; i<=n; i++){
fin>>v[i];
}
fin>>t;
while(t){
fin>>x>>y;
st=0;
p=(1<<20);
if(x==0){
while(p){
if(st+p<=n && v[st+p]<=y){
st+=p;
}
p=p/2;
}
if(v[st]==y){
fout<<st<<"\n";
}else{
fout<<-1<<"\n";
}
}
if(x==1){
while(p){
if(st+p<=n && v[st+p]<=y){
st+=p;
}
p=p/2;
}
fout<<st<<"\n";
}
if(x==2){
while(p){
if(st+p<=n && v[st+p]<y){
st+=p;
}
p=p/2;
}
fout<<st+1<<"\n";
}
t--;
}
}