Pagini recente » Cod sursa (job #201971) | Cod sursa (job #453076) | Istoria paginii runda/oni_2017_cl10_ziua1/clasament | Cod sursa (job #3253456) | Cod sursa (job #201533)
Cod sursa(job #201533)
#include<stdio.h>
#include<stdlib.h>
#define NMAX 100000
#define MMAX 100000
struct qry{int tip,x;};
int v[NMAX+1],n,m;
qry w[MMAX+1];
int main(){
freopen("cautbin.in","r",stdin);
freopen("cautbin.out","w",stdout);
scanf("%d",&n);
int i,j,r;
for(i=1;i<=n;i++) scanf("%d",&v[i]);
scanf("%d",&m);
for(j=1;j<=m;j++) scanf("%d%d",&w[j].tip,&w[j].x);
for(j=1;j<=m;j++){
r=-1;
switch(w[j].tip){
case 0: r=-1;
for(i=1;i<=n;i++)
if(w[j].x==v[i]) {r=i;break;}
break;
case 1: r=n;
for(i=1;i<=n;i++)
if(v[i]>w[j].x) {r=i-1;break;}
break;
case 2: r=1;
for(i=n;i>0;i--)
if(v[i]<w[j].x) {r=i+1;break;}
break;
}
printf("%d\n",r);
}
return 0;
}