Pagini recente » Cod sursa (job #290470) | Cod sursa (job #478974) | Cod sursa (job #478977) | Cod sursa (job #78833) | Cod sursa (job #2072489)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int n,m,i,t[100001], s,d,mij,x,tip,poz;
void c0(int x)
{
s=1;
d=n;
poz=-1;
while (s<=d)
{
mij=s+(d-s)/2;
if (x==t[mij])
poz=mij;
if (x>=t[mij])
s=mij+1;
else d=mij-1;
}
fout<<poz<<endl;
}
void c1(int x)
{
s=1;
d=n;
poz=-1;
while (s<=d)
{
mij=s+(d-s)/2;
if (x>=t[mij])
{
poz=mij;
s=mij+1;
}
else d=mij-1;
}
fout<<poz<<endl;
}
void c2(int x)
{
s=1;
d=n;
poz=-1;
while (s<=d)
{
mij=s+(d-s)/2;
if (x<=t[mij])
{
poz=mij;
d=mij-1;
}
else s=mij+1;
}
fout<<poz<<endl;
}
int main()
{
fin>>n;
for (i=1;i<=n;i++)
fin>>t[i];
fin>>m;
for (i=1;i<=m;i++)
{
fin>>tip>>x;
if (tip==0)
c0(x);
else if (tip==1)
c1(x);
else
c2(x);
}
return 0;
}