Pagini recente » Cod sursa (job #730919) | Cod sursa (job #686737) | Cod sursa (job #1633107) | Cod sursa (job #773484) | Cod sursa (job #798808)
Cod sursa(job #798808)
#include <cstdio>
using namespace std;
long a[100001];
int main () {
long n,i,m,k,x,step,j;
freopen ("cautbin.in","r",stdin);
freopen ("cautbin.out","w",stdout);
scanf ("%ld",&n);
for (i=1;i<=n;i++)
scanf ("%ld",&a[i]);
scanf ("%ld",&m);
for (i=1;i<=m;i++) {
scanf ("%ld%ld",&k,&x);
if (k==0) {
step=1<<16;
for (j=0;step;step>>=1) {
if (j+step<=n && a[j+step]<=x)
j=j+step;
}
if (a[j]==x)
printf ("%ld\n",j);
else printf ("-1\n");
}
if (k==1) {
step=1<<16;
for (j=0;step;step>>=1) {
if (j+step<=n && a[j+step]<=x)
j=j+step;
}
printf ("%ld\n",j);
}
if (k==2) {
step=1<<16;
for (j=0;step;step>>=1) {
if (j+step<=n && a[j+step]<x)
j=j+step;
}
printf ("%ld\n",j+1);
}
}
return 0;
}