Pagini recente » Istoria paginii runda/cerculdeinfo-lectia2-arborideintervale/clasament | Cod sursa (job #1490167) | Profil Penalu | Cod sursa (job #2357263) | Cod sursa (job #2982392)
#include <bits/stdc++.h>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int v[100005],n,m,cer,x;
int cb1(int st, int dr, int x)
{
int mj=0,poz=0;
while(st<=dr)
{
mj=(st+dr)/2;
if(v[mj]==x)
poz=mj,st=mj+1;
if(v[mj]>x)
dr=mj-1;
if(v[mj]<x)
st=mj+1;
}
return poz;
}
int cb2(int st, int dr, int x)
{
int mj=0,poz=0;
while(st<=dr)
{
mj=(st+dr)/2;
if(v[mj]<=x)
poz=mj,st=mj+1;
else
dr=mj-1;
}
return poz;
}
int cb3(int st, int dr, int x)
{
int mj=0,poz=0;
while(st<=dr)
{
mj=(st+dr)/2;
if(v[mj]>=x)
poz=mj,dr=mj-1;
else
st=mj+1;
}
return poz;
}
int main()
{
f>>n;
for(int i=1;i<=n;i++)
f>>v[i];
f>>m;
for(int i=1;i<=m;i++)
{
f>>cer>>x;
if(cer==0)
g<<cb1(1,n,x)<<'\n';
if(cer==1)
g<<cb2(1,n,x)<<'\n';
if(cer==2)
g<<cb3(1,n,x)<<'\n';
}
return 0;
}