Pagini recente » Cod sursa (job #1321453) | Cod sursa (job #2191374) | Cod sursa (job #2238787) | Cod sursa (job #2481846) | Cod sursa (job #1878041)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream cin ("cautbin.in");
ofstream cout("cautbin.out");
vector <int> a;
int m,x,y;
void read()
{
int n;
cin >> n;
a.resize(n);
for (int i=0; i<a.size(); cin >> a[i++]);
}
main()
{
read();
vector <int> :: iterator i;
cin >> m;
for (; m ; m--)
{
cin >> x >> y;
if (x==0)
{
if (binary_search(a.begin(),a.end(),y))
cout << upper_bound(a.begin(),a.end(),y)-a.begin() << '\n';
else cout << "-1\n";
}
if (x==1) cout << lower_bound(a.begin(), a.end(), y + 1) - a.begin() << '\n';
if (x==2) cout << upper_bound(a.begin(), a.end(), y - 1) - a.begin()+1 << '\n';
}
}