Pagini recente » Cod sursa (job #322017) | Cod sursa (job #2738254) | Cod sursa (job #3258120) | Cod sursa (job #3272851) | Cod sursa (job #3272123)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int arr[100000];
int main()
{
int n, m, c, x, l, r, mij, pos;
fin >> n;
for (int i=0; i<n; i++) fin >> arr[i];
fin >> m;
for (int i=1; i<=m; i++) {
fin >> c >> x;
if (c == 0 || c == 1) {
pos = upper_bound(arr, arr + n, x) - arr;
if (c == 0 && arr[pos - 1] != x) fout << "-1\n";
else fout << pos << endl;
}
else {
pos = lower_bound(arr, arr + n, x) - arr;
fout << pos + 1;
}
}
}