Pagini recente » Rating Barbu Matei (Barbumatei) | Cod sursa (job #3293569) | Cod sursa (job #1185698)
#include <cstdio>
#include <algorithm>
const int NMAX = 100005;
int V[NMAX];
int main()
{
freopen("cautbin.in", "r", stdin);
freopen("cautbin.out", "w", stdout);
int N, M;
int i;
scanf("%d", &N);
for (i = 0; i < N; ++i)
scanf("%d", &V[i]);
scanf("%d", &M);
for (; M; --M) {
int type, x;
int ret;
scanf("%d %d", &type, &x);
if (type == 0) {
int ret = std::upper_bound(V, V+N, x) - V - 1;
if (V[ret] != x)
printf("-1\n");
else
printf("%d\n", ret + 1);
} else if (type == 1) {
int ret = (std::lower_bound(V, V+N, x+1) - V - 1);
printf("%d\n", ret + 1);
} else {
int ret = (std::upper_bound(V, V+N, x-1) - V) + 1;
printf("%d\n", ret + 1);
}
}
return 0;
}