Pagini recente » Cod sursa (job #2840297) | Cod sursa (job #968169) | Cod sursa (job #114510) | Cod sursa (job #3178427) | Cod sursa (job #2775824)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("cautbin.in");
ofstream fout ("cautbin.out");
void usain_bolt()
{
ios::sync_with_stdio(false);
fin.tie(0);
}
const int N = 1e5 + 5;
int a[N];
int main()
{
usain_bolt();
int n, m;
fin >> n;
for(int i = 1; i <= n; ++i) {
fin >> a[i];
}
fin >> m;
for(; m; --m) {
int type, x;
fin >> type >> x;
if(type == 0) {
int pos = upper_bound(a + 1, a + 1 + n, x) - a;
if(pos <= 1 || a[pos - 1] != x) {
fout << -1 << "\n";
}
else {
fout << pos - 1 << "\n";
}
}
else if(type == 1) {
int pos = upper_bound(a + 1, a + 1 + n, x) - a - 1;
fout << pos << "\n";
}
else {
int pos = lower_bound(a + 1, a + 1 + n, x) - a;
if(a[pos] < x) {
++pos;
}
fout << pos << "\n";
}
}
return 0;
}