Pagini recente » Cod sursa (job #56145) | Cod sursa (job #2728769) | Cod sursa (job #2932094) | Cod sursa (job #2135442) | Cod sursa (job #1130575)
#include <stdio.h>
#include <algorithm>
using namespace std;
int V[100100];
int main () {
int N, M, x, y, i, t;
freopen("cautbin.in", "r", stdin);
freopen("cautbin.out", "w", stdout);
scanf("%d", &N);
for (i = 1; i <= N; ++ i)
scanf("%d", &V[i]);
sort(V + 1, V + N + 1);
scanf("%d", &M);
for (i = 1; i <= M; ++ i) {
scanf("%d%d", &t, &y);
if (t == 0) {
x = upper_bound(V + 1, V + N + 1, y) - V - 1;
if (x <= N && x >= 1 && V[x] == y)
printf("%d\n", x);
else
printf("-1\n");
} else if (t == 1) {
x = lower_bound(V + 1, V + N + 1, y + 1) - V - 1;
printf("%d\n", x);
} else {
x = upper_bound(V + 1, V + N + 1, y - 1) - V;
printf("%d\n", x);
}
}
}
/*#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>
#include<set>
#include<map>
using namespace std ;
#define maxn 100005
int N ;
int v[maxn] ;
int Q ;
int main()
{
std::ios_base::sync_with_stdio(false) ;
freopen("cautbin.in", "r", stdin);
freopen("cautbin.out", "w", stdout);
cin >> N ;
for(int i = 1; i <= N; ++i )
cin >> v[i] ;
sort( v + 1, v + N + 1 ) ;
cin >> Q ;
while( Q-- )
{
int op, x ;
cin >> op >> x ;
if( op == 0 )
{
int sol = upper_bound( v + 1, v + N + 1, x ) - v - 1 ;
if( sol <= N && sol >= 1 && v[sol] == x )
cout << sol << "\n" ;
else
cout << "-1\n" ;
}
if( op == 1 )
{
int sol = lower_bound( v + 1, v + N + 1, x + 1 ) - v - 1 ;
cout << sol << "\n" ;
}
if( op == 2 )
{
int sol = upper_bound( v + 1, v + N + 1, x - 1 ) - v ;
cout << sol << "\n" ;
}
}
return 0 ;
}*/