Pagini recente » Cod sursa (job #2469431) | Cod sursa (job #1808250) | Cod sursa (job #3209621) | Cod sursa (job #1072918) | Cod sursa (job #3302725)
#include <bits/stdc++.h>
/// Template Dutzu
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int v[100005];
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,x;
fin>>a>>x;
if (a==0)
{
int st=1,dr=n,mij,rez=-1;
while(st<=dr)
{
mij=st+(dr-st)/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=st+(dr-st)/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=st+(dr-st)/2;
if (v[mij]>=x)
{
dr=mij-1;
rez=mij;
}
else
st=mij+1;
}
fout<<rez<<'\n';
}
}
return 0;
}