Pagini recente » Cod sursa (job #1280408) | Cod sursa (job #1428696) | Cod sursa (job #1340657) | Cod sursa (job #2235270) | Cod sursa (job #2550132)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("cautbin.in");
ofstream out("cautbin.out");
unsigned int m,n,v[100001],i,j,e,x,c,mij;
int div0(int p,int q){
if(p==q){if(v[p]==x)return p;else return -1;}
else {
mij=(p+q)/2;
if(x>=v[mij+1])div0(mij+1,q);
else div0(p,mij);
}
}
int div1(int p,int q){
if(p==q)return p;
else {
mij=(p+q)/2;
if(x>=v[mij+1])div1(mij+1,q);
else div1(p,mij);
}
}
int div2(int p,int q){
if(p==q)return p;
else {
mij=(p+q)/2;
if(x<=v[mij])div2(p,mij);
else div2(mij+1,q);
}
}
int main()
{
in>>n;
for(i=1;i<=n;i++)in>>v[i];
in>>m;
for(e=1;e<=m;e++){
in>>c>>x;
if(c==0)out<<div0(1,n)<<'\n';
if(c==1)out<<div1(1,n)<<'\n';
if(c==2)out<<div2(1,n)<<'\n';
}
in.close();
out.close();
return 0;
}