Pagini recente » Cod sursa (job #322112) | Cod sursa (job #8696) | Cod sursa (job #772464) | Cod sursa (job #197367)
Cod sursa(job #197367)
#include<stdio.h>
int n,m,op,x,i,v[100001];
int calc_solutie(int op, int x)
{
int st=1;
int dr=n;
while(st<=dr)
{
int mid=st+(dr-st)/2;
if (v[mid]>x) dr=mid-1;
else if (v[mid]<x) st=mid+1;
else return mid;
}
switch(op)
{
case 0: return -1;
case 1: return st-1;
case 2: return st;
}
return 0; }
int main()
{
freopen("cautbin.in","r",stdin);
freopen("cautbin.out","w",stdout);
scanf("%i",&n);
for(i=1;i<=n;scanf("%i",&v[i++]));
scanf("%i",&m);
for(i=1;i<=m;i++){
scanf("%i %i",&op,&x);
printf("%i \n",calc_solutie(op,x));
}
fclose(stdin);
fclose(stdout);
return 0;
}