Pagini recente » Cod sursa (job #1143071) | Cod sursa (job #2329344) | Cod sursa (job #1780436) | Cod sursa (job #1813089) | Cod sursa (job #2445559)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream cin("cautbin.in");
ofstream cout("cautbin.out");
int n, m;
vector<int> v;
void citire()
{
int x;
cin >> n;
for(int i = 1 ; i <= n ; i++)
cin >> x, v.push_back(x);
sort(v.begin(), v.end());
cin >> m;
}
void rez()
{
int x, y;
for(int i = 1 ; i <= m ; i++)
{
cin >> x >> y;
if(!x)
{
int lw = upper_bound(v.begin(), v.end(), y) - v.begin();
(v[lw - 1] == y && lw != 0) ? cout << lw << '\n' : cout << -1 << '\n';
}
else if(x == 1)
cout << upper_bound(v.begin(), v.end(), y) - v.begin() << '\n';
else if(x == 2)
cout << lower_bound(v.begin(), v.end(), y) - v.begin() + 1 << '\n';
}
}
int main()
{
citire();
rez();
return 0;
}