Pagini recente » Cod sursa (job #1364884) | Cod sursa (job #2659200) | Cod sursa (job #1448078) | Cod sursa (job #3232023) | Cod sursa (job #2484666)
#include<fstream>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n,v[100001],m,contor,x,in,sf,mij,poz;
int main()
{
//ios::sync_with_stdio(false);
f>>n;
for(int i=1; i<=n; i++)
f>>v[i];
f>>m;
while(m--)
{
f>>contor>>x;
in = 1;
sf = n;
poz=0;
if(contor==0)
{
while(sf>=in)
{
mij=(in+sf)/2;
if(v[mij]<=x)
{
poz=mij;
in=mij+1;
}
else
sf=mij-1;
}
if(v[poz]==x)
g<<poz<<"\n";
else
g<<"-1"<<"\n";
}
if(contor==1)
{
while(sf>=in)
{
mij=(in+sf)/2;
if(v[mij]<=x)
{
poz=mij;
in=mij+1;
}
else
sf=mij-1;
}
g<<poz<<"\n";
}
if(contor==2)
{
while(sf>=in)
{
mij=(in+sf)/2;
if(v[mij]>=x)
{
poz=mij;
sf=mij-1;
}
else
in=mij+1;
}
g<<poz<<"\n";
}
}
return 0;
}