Pagini recente » Cod sursa (job #2808329) | Cod sursa (job #3263382) | Cod sursa (job #1928370) | Cod sursa (job #1492378) | Cod sursa (job #2682116)
#include <fstream>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
const int NMAX=100005;
int v[NMAX];
int main()
{
int n,m,x,y,i,st,dr,mij,rez;
fin>>n;
for(i=1;i<=n;i++)
fin>>v[i];
fin>>m;
while(m!=0){
fin>>x>>y;
st=1;
dr=n;
if(x==0 || x==1)
{
while(st<=dr)
{
mij=(st+dr)/2;
if(v[mij]<=y)
{
rez=mij;
st=mij+1;
}
else
dr=mij-1;
}
if(x==0)
{
if(v[rez]==y)
fout<<rez<<endl;
else
fout<<"-1"<<endl;
}
if(x==1)
fout<<rez<<endl;
}
if(x==2)
{
while(st<=dr)
{
mij=(st+dr)/2;
if(v[mij]>=y){
rez=mij;
dr=mij-1;
}
else
st=mij+1;
}
fout<<rez<<endl;
}
m--;
}
return 0;
}