Cod sursa(job #902297)
#include<cstdio>
#include<algorithm>
using namespace std;
int v[100002],n,m;
int main()
{
freopen("cautbin.in","r",stdin);
freopen("cautbin.out","w",stdout);
scanf("%d",&n);
for(int i=0;i<n;++i)scanf("%d",&v[i]);
scanf("%d",&m);
for(int i=0;i<m;++i)
{
int c,x,poz;
scanf("%d%d",&c,&x);
if(c==0)
{
poz=upper_bound(v,v+n,x)-v-1;
if(poz>=0&&poz<n&&v[poz]==x)printf("%d\n",poz+1);
else printf("-1\n");
}
if(c==1)
{
poz=lower_bound(v,v+n,x+1)-v-1;
printf("%d\n",poz+1);
}
if(c==2)
{
poz=upper_bound(v,v+n,x-1)-v;
printf("%d\n",poz+1);
}
}
return 0;
}