Cod sursa(job #1010922)
| Utilizator | Data | 15 octombrie 2013 21:34:57 | |
|---|---|---|---|
| Problema | Cautare binara | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.68 kb |
#include <stdio.h>
#include <algorithm>
#define N 100000
#define fr(i,a,b) for(int i=a;i<b;++i)
using namespace std;
int a[N];
int main(){
freopen("cautbin.in","r",stdin);
freopen("cautbin.out","w",stdout);
int n,m;
scanf("%i",&n);
fr(i,0,n)scanf("%i",a+i);
scanf("%i",&m);
int x,y;
fr(i,0,m){
scanf("%i%i",&x,&y);
if(x==0){
x=upper_bound(a,a+n,y)-a;
x=a[x-1]==y?x:-1;
}
else if(x==1){
x=upper_bound(a,a+n,y)-a;
}
else if(x==2){
x=1+upper_bound(a,a+n,y-1)-a;
}
printf("%i\n",x);
}
return 0;
}
