Pagini recente » Cod sursa (job #2892243) | Cod sursa (job #905834)
Cod sursa(job #905834)
#include <fstream>
#include <algorithm>
#include <vector>
#include <iostream>
using std::cout;
using std::vector;
using std::lower_bound;
using std::upper_bound;
std::ifstream in("cautbin.in");
std::ofstream out("cautbin.out");
vector<int> a;
int N,M;
int main()
{
in >> N;
for (int i = 0; i < N; ++i) {
int x; in >> x;
a.push_back(x);
}
in >> M;
for (int i = 0; i < M; ++i)
{
int x,y; in >> x >> y;
if ( x == 0 ) {
int p = lower_bound(a.begin(), a.end(), y + 1) - a.begin();
if ( a[p - 1] == y ) out << p << '\n';
else out << -1 << '\n';
} else if ( x == 1 ) {
int p = lower_bound(a.begin(), a.end(), y + 1) - a.begin();
out << p << '\n';
} else if ( x == 2 ) {
int p = upper_bound(a.begin(), a.end(), y - 1) - a.begin() + 1;
out << p << '\n';
}
}
in.close();
out.close();
return 0;
}