Cod sursa(job #947501)
#include <cassert>
#include <cstdlib>
#include <fstream>
#include <algorithm>
using namespace std;
const int NMAX = 100011;
int v[NMAX];
int main()
{
int N, M, op, x, i;
ifstream in("cautbin.in");
ofstream out("cautbin.out");
in >> N;
for(i = 1; i <= N; ++i) in >> v[i];
assert(is_sorted(v + 1, v + N + 1));
for(in >> M; M; --M)
{
in >> op >> x;
auto y = equal_range(v + 1, v + N + 1, x);
if(0 == op)
{
if(v + N + 1 == y.first || x != *y.first) out << "-1\n";
else out << (y.second - v - 1) << '\n';
}
else if(1 == op) out << (y.second - v - 1) << '\n';
else out << (y.first - v) << '\n';
}
return EXIT_SUCCESS;
}