Pagini recente » Cod sursa (job #3279359) | Cod sursa (job #2720122) | Cod sursa (job #280939) | Cod sursa (job #2915016) | Cod sursa (job #3005434)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("cautbin.in");
ofstream out("cautbin.out");
#define MAX 100000
int v[MAX+1];
int main()
{
int n,m,i,x,y,st,dr,mij,poz;
in>>n;
for(i=0; i<n; ++i)
in>>v[i];
in>>m;
for(i=0; i<m; ++i)
{
in>>y>>x;
if(y==0)
{
st=0;
dr=n;
while(dr-st>1)
{
mij=(st+dr)/2;
if(v[mij]>x)
dr=mij;
else
st=mij;
}
if(v[st]==x)
out<<st+1<<endl;
else
out<<-1<<endl;
}
else if(y==1)
{
st=0;
dr=n;
while(dr-st>1)
{
mij=(st+dr)/2;
if(v[mij]>x)
dr=mij;
else
st=mij;
}
if(v[st]==x)
out<<st+1<<endl;
else
out<<-1<<endl;
}
else if(y==2)
{
poz=-1;
st=0;
dr=n;
while(dr-st>1)
{
mij=(st+dr)/2;
if(v[mij]>=x)
{
dr=mij;
poz=mij+1;
}
else
st=mij;
}
out<<poz<<endl;
}
}
return 0;
}