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