Pagini recente » Cod sursa (job #2436168) | Cod sursa (job #2975376) | Clasament Teme ACM Unibuc 2013 | Cod sursa (job #3232691) | Cod sursa (job #2162357)
#include<fstream>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int a[100001],dr,st,intrebarea,x,m,n,i,mij;
int main()
{
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
f>>m;
for(i=1;i<=m;i++)
{
st=0;
dr=n;
f>>intrebarea>>x;
if(intrebarea==0)
{
while(st<=dr)
{
mij=st+(dr-st)/2;
if (a[mij]<=x)
st=mij+1;
else
dr=mij-1;
}
if (a[dr]==x)
g<<dr<<"\n";
else
g<<-1<<'\n';
}
if(intrebarea==1)
{
while(st<=dr)
{
mij=st+(dr-st)/2;
if(a[mij]<=x)
st=mij+1;
else
dr=mij-1;
}
g<<dr<<'\n';
}
if(intrebarea==2)
{
while(st<=dr)
{
mij=st+(dr-st)/2;
if(a[mij]<x)
st=mij+1;
else
dr=mij-1;
}
g<<st<<'\n';
}
}
}