Pagini recente » Cod sursa (job #666693) | Cod sursa (job #666600) | Cod sursa (job #666617) | Cod sursa (job #3274981) | Cod sursa (job #3232163)
#include <bits/stdc++.h>
using namespace std;
const int N = (int) 1e5 + 7;
int n, a[N];
int cntunder(int x) {
int l = 1, r = n, cnt = 0;
while (l <= r) {
int m = (l + r) / 2;
if (a[m] <= x) {
cnt = m;
l = m + 1;
} else {
r = m - 1;
}
}
return cnt;
}
int main() {
#ifdef INFOARENA
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
freopen ("cautbin.in", "r", stdin);
freopen ("cautbin.out", "w", stdout);
#endif
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int q;
cin >> q;
while (q--) {
int tp, x;
cin >> tp >> x;
if (tp == 0) {
int cnt = cntunder(x);
if (cnt && a[cnt] == x) {
cout << cnt << "\n";
} else {
cout << "-1\n";
}
continue;
}
if (tp == 1) {
cout << cntunder(x) << "\n";
continue;
}
assert(tp == 2);
cout << cntunder(x - 1) + 1 << "\n";
}
return 0;
}