Pagini recente » Cod sursa (job #113005) | Cod sursa (job #62225) | Cod sursa (job #6869) | Cod sursa (job #1638846) | Cod sursa (job #2985784)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int n, x, m;
vector<int> a;
int main()
{
fin >> n;
for (int i = 0 ; i < n; i++)
{
int temp;
fin >> temp;
a.push_back(temp);
}
fin >> m;
for (int i = 0; i < m; i++)
{
int x, y;
fin >> x >> y;
if (x == 0)
{
int low = *upper_bound(a.begin(), a.end(), y) - 1;
if (a[low - 1] != y)
{
fout << -1 << '\n';
}
else
{
fout << low << '\n';
}
}
else if (x == 1)
{
fout << *upper_bound(a.begin(), a.end(), y) - 1 << '\n';
}
else
{
fout << a[*lower_bound(a.begin(), a.end(), y)] << '\n';
}
}
return 0;
}