Pagini recente » Cod sursa (job #35907) | Cod sursa (job #229311)
Cod sursa(job #229311)
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAXN 100005
int N, M;
int v[MAXN];
int main()
{
freopen("cautbin.in", "rt", stdin);
freopen("cautbin.out", "wt", 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 type, val;
scanf("%d %d", &type, &val);
if (type == 0)
{
int poz = lower_bound(v, v + N, val) - v;
if (v[poz] == val)
printf("%d\n", poz + 1);
else
printf("-1\n");
}
if (type == 1)
printf("%d\n", lower_bound(v, v + N, val) - v);
if (type == 2)
printf("%d\n", lower_bound(v, v + N, val - 1) - v + 1);
}
return 0;
}