Pagini recente » Cod sursa (job #2575904) | Cod sursa (job #2575922) | Istoria paginii runda/aaaaaaaaaaaaaaaaaaaa/clasament | Cod sursa (job #239821) | Cod sursa (job #1316878)
#include <cstdio>
#include <algorithm>
#define MAXN 100100
using namespace std;
int V[MAXN], n,m;
void rezolva_problema()
{
int i, t, x, y;
scanf("%d", &n);
for(i=1;i<=n;++i)
scanf("%d", &V[i]);
scanf("%d", &m);
for(i=1;i<=m;++i)
{
scanf("%d%d", &t, &x);
if(t==0)
{
y=upper_bound(V+1, V+n+1, x) - V-1;
if(y>=1&&y<=n&&V[y]==x)
printf("%d\n", y);
else
printf("-1\n");
}
else
if(t==1)
{
y=lower_bound(V+1, V+n+1, x+1)-V-1;
printf("%d\n", y);
}
else
{
y=upper_bound(V+1, V+n+1, x-1)-V;
printf("%d\n", y);
}
}
}
int main()
{
freopen("cautbin.in", "r", stdin);
freopen("cautbin.out", "w", stdout);
rezolva_problema();
return 0;
}