Pagini recente » Cod sursa (job #3260757) | Cod sursa (job #1930867) | Cod sursa (job #3525) | Cod sursa (job #2381792) | Cod sursa (job #716482)
Cod sursa(job #716482)
#include<cstdio>
#include<algorithm>
#include<vector>
#define nmax 100001
using namespace std;
int n,m,key,x,v[nmax];
int main()
{
int i, poz;
freopen("cautbin.in","r",stdin);
freopen("cautbin.out","w",stdout);
scanf("%d", &n);
for(i=0;i<n;i++)
scanf("%d", &v[i]);
scanf("%d", &m);
for(i=1;i<=m;i++)
{
scanf("%d%d", &key, &x);
if(key==0)
{
poz=upper_bound(v,v+n,x)-v;
if(poz>=1&&poz<=n&&v[poz-1]==x)
printf("%d\n",poz);
else
printf("-1\n");
continue;
}
if(key==1)
{
poz=upper_bound(v,v+n,x+1)-v;
printf("%d\n", poz);
}
if(key==2)
{
poz=lower_bound(v,v+n,x-1)-v+1;
printf("%d\n",poz);
}
}
return 0;
}