Pagini recente » Cod sursa (job #1444619) | Cod sursa (job #335056) | Cod sursa (job #3037745) | Cod sursa (job #160167) | Cod sursa (job #201176)
Cod sursa(job #201176)
#include <cstdio>
const int N = 100000;
int n,m;
int a[N];
int main() {
freopen("cautbin.in","rt",stdin);
freopen("cautbin.out","wt",stdout);
scanf("%d",&n);
for (int i = 0; i < n; ++i) scanf("%d",&a[i]);
scanf("%d",&m);
for (int i = 0, c, x; i < m; ++i) {
scanf("%d %d",&c,&x);
if (c == 0 || c == 1) {
int p = 0, step = 1 << 16;
for (; step; step >>= 1)
if (p + step < n && a[p+step] <= x)
p += step;
if (c == 0 && a[p] != x)
printf("-1\n"); else
printf("%d\n",p+1);
} else {
int p = 0, step = 1 << 16;
for (; step; step >>= 1)
if (p + step < n && a[p+step] < x)
p += step;
printf("%d\n",p+2);
}
}
}