Pagini recente » Cod sursa (job #2540303) | Cod sursa (job #3235835) | Cod sursa (job #2957858) | Cod sursa (job #590478) | Cod sursa (job #1313287)
#include <iostream>
#include <cstdio>
#include <algorithm>
#define n_max 100005
using namespace std;
int n , v[n_max] ;
void citire() ;
void parcurgere() ;
int main()
{
freopen( "cautbin.in" , "r" , stdin ) ;
freopen( "cautbin.out" , "w" , stdout ) ;
citire() ;
parcurgere() ;
return 0;
}
void citire()
{
scanf( "%d" , &n ) ;
for ( int i = 0 ; i < n ; i ++ )
scanf( "%d" , &v[i] ) ;
sort( v , v + n ) ;
}
void parcurgere()
{
int k ;
scanf( "%d" , &k ) ;
while(k--)
{
int t , nr ;
scanf( "%d %d" , &t , &nr ) ;
if ( t == 0 )
{
int x = upper_bound( v , v + n , nr ) - v - 1 ;
if ( v[x] == nr )
printf( "%d\n" , x + 1 ) ;
else
printf( "-1\n" ) ;
}
else if ( t == 1 )
{
int x = lower_bound( v , v + n , nr + 1 ) - v - 1 ;
printf( "%d\n" , x + 1 ) ;
}
else
{
int x = upper_bound( v , v + n , nr - 1 ) - v ;
printf( "%d\n" , x + 1 ) ;
}
}
}