Pagini recente » Atasamentele paginii Profil AlexandruNNN | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #3366985) | Cod sursa (job #3365640)
#include <bits/stdc++.h>
void solve()
{
int n;
std::cin >> n;
std::vector<int> v(n);
for (auto &c : v) {
std::cin >> c;
}
int q;
std::cin >> q;
while (q--) {
int cer, val;
std::cin >> cer >> val;
if (cer == 0) {
int poz = std::lower_bound(v.begin(), v.end(), val + 1) - v.begin();
if (poz == 0 || v[poz - 1] != val) {
std::cout << -1 << '\n';
} else {
std::cout << poz << '\n';
}
} else if (cer == 1) {
int poz = std::lower_bound(v.begin(), v.end(), val + 1) - v.begin();
std::cout << poz << '\n';
} else {
int poz = std::lower_bound(v.begin(), v.end(), val) - v.begin();
std::cout << poz + 1 << '\n';
}
}
}
signed main(void)
{
freopen("cautbin.in", "r", stdin);
freopen("cautbin.out", "w", stdout);
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int tt = 1;
while (tt--) {
solve();
}
}