Pagini recente » Cod sursa (job #1303025) | Cod sursa (job #2652614) | Cod sursa (job #1455289) | Cod sursa (job #805821) | Cod sursa (job #3302724)
#include <bits/stdc++.h>
/// Template Dutzu
using namespace std;
ifstream fin("teste.in");
ofstream fout("teste.out");
int v[100001],x;
int main()
{
int n,m;
fin>>n;
for (int i=1;i<=n;i++)
fin>>v[i];
fin>>m;
for (int i=1;i<=m;i++)
{
int a;
fin>>a>>x;
if (a==0)
{
int st=1,dr=n,mij,rez=-1;
while(st<=dr)
{
mij=1LL*(st+dr)/2;
if (v[mij]<=x)
{
st=mij+1;
if (v[mij]==x)
rez=mij;
}
else
dr=mij-1;
}
fout<<rez<<'\n';
}
if (a==1)
{
int st=1,dr=n,mij,rez;
while(st<=dr)
{
mij=1LL*(st+dr)/2;
if (v[mij]<=x)
{
st=mij+1;
rez=mij;
}
else
dr=mij-1;
}
fout<<rez<<'\n';
}
if (a==2)
{
int st=1,dr=n,mij,rez;
while(st<=dr)
{
mij=1LL*(st+dr)/2;
if (v[mij]>=x)
{
dr=mij-1;
rez=mij;
}
else
st=mij+1;
}
fout<<rez<<'\n';
}
}
return 0;
}