Pagini recente » Cod sursa (job #1377543) | Cod sursa (job #947583) | Cod sursa (job #1008569) | Cod sursa (job #2646585)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("cautbin.in");
ofstream fout ("cautbin.out");
const int DIM = 100000 + 5;
int a[DIM];
int main()
{
int n, m;
fin >> n;
for(int i = 1; i <= n; ++i) {
fin >> a[i];
}
fin >> m;
for(int i = 1; i <= m; ++i) {
int type, x;
fin >> type >> x;
if(type == 0) {
int pos = upper_bound(a + 1, a + 1 + n, x) - a;
--pos;
if(a[pos] != x) fout << "-1" << "\n";
else fout << pos << "\n";
}
else if(type == 1) {
int pos = lower_bound(a + 1, a + 1 + n, x + 1) - a;
--pos;
fout << pos << "\n";
}
else if(type == 2) {
int pos = lower_bound(a + 1, a + 1 + n, x) - a;
fout << pos << "\n";
}
}
return 0;
}