Pagini recente » Cod sursa (job #1898550) | Cod sursa (job #879154) | Cod sursa (job #2409937) | Cod sursa (job #671169) | Cod sursa (job #1922508)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
int N, Q;
vector<int> V;
int main()
{
ifstream i("cautbin.in");
ofstream o("cautbin.out");
i >> N;
for(int a = 0; a < N; a++)
{
int x;
i >> x;
V.push_back(x);
}
sort(V.begin(), V.end());
i >> Q;
for(int a = 0; a < Q; a++)
{
std::vector<int>::iterator k;
int x, y;
i >> x >> y;
if(x == 0)
{
k = upper_bound(V.begin(), V.end(), y);
if(*(k - 1) == y)
cout << k - V.begin() << '\n';
else
cout << "-1" << '\n';
}
else if(x == 1)
{
k = upper_bound(V.begin(), V.end(), y);
cout << k - V.begin() << '\n';
}
else
{
k = lower_bound(V.begin(), V.end(), y);
cout << k - V.begin() + 1 << '\n';
}
}
return 0;
}