Pagini recente » Istoria paginii runda/oni_2009_baraj | Cod sursa (job #1671211) | Cod sursa (job #516243) | Monitorul de evaluare | Cod sursa (job #556388)
Cod sursa(job #556388)
# include <algorithm>
# include <cstdio>
# define lb std :: lower_bound
# define ub std :: upper_bound
const char *FIN = "cautbin.in", *FOU = "cautbin.out" ;
const int MAX = 100005 ;
int V[MAX] ;
int N, tip, X, T ;
int main ( void ) {
freopen ( FIN, "r", stdin ) ;
freopen ( FOU, "w", stdout ) ;
scanf ( "%d", &N ) ;
for ( int i = 0; i < N; ++i ) {
scanf ( "%d", V + i ) ;
}
for ( scanf ( "%d", &T ) ; T ; --T ) {
scanf ( "%d %d", &tip, &X ) ;
if ( tip == 0 ) {
int aux = ub ( V , V + N , X ) - V - 1 ;
printf ( "%d\n", aux >= 0 && aux < N && V[aux] == X ? aux + 1 : -1 ) ;
} else if ( tip == 1 ) {
printf ( "%d\n", lb ( V , V + N , X + 1 ) - V ) ;
} else {
printf ( "%d\n", ub ( V , V + N , X - 1 ) - V + 1 ) ;
}
}
}