Pagini recente » Cod sursa (job #777923) | Cod sursa (job #982103) | Monitorul de evaluare | Cod sursa (job #2257550) | Cod sursa (job #2386883)
#include <bits/stdc++.h>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int main()
{
int n; f >> n;
int vect[n];
for(int i = 0; i<n; i++)
f >> vect[i];
int intrebari; f >> intrebari;
for(int i = 0; i<intrebari; i++){
int q, x; f >> q >> x;
if(q==0){
if(vect[(upper_bound(vect, vect+n, x)-vect-1)]!=x) cout << -1 << endl;
else g << upper_bound(vect, vect+n, x)-vect << endl;
}
if(q==1) g << upper_bound(vect, vect+n, x)-vect << endl;
if(q==2) g << lower_bound(vect, vect+n, x)-vect+1 << endl;
}
}