Pagini recente » Cod sursa (job #423208) | Cod sursa (job #479140) | Cod sursa (job #490550) | Cod sursa (job #2762468) | Cod sursa (job #3212498)
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << ": " << x << "\n";
#define sz(x) ((int)x.size())
using ll = long long;
const string fn = "cautbin";
ifstream fin(fn + ".in");
ofstream fout(fn + ".out");
int n;
int a[100005];
int main()
{
fin >> n;
for (int i = 1; i <= n; ++i)
fin >> a[i];
int m;
fin >> m;
while (m--)
{
int op, x;
fin >> op >> x;
if (op == 0)
fout << (a[upper_bound(a + 1, a + n + 1, x) - a - 1] == x ? upper_bound(a + 1, a + n + 1, x) - a - 1 : -1) << '\n';
else if (op == 1)
fout << upper_bound(a + 1, a + n + 1, x) - a - 1 << '\n';
else
fout << lower_bound(a + 1, a + n + 1, x) - a << '\n';
}
return 0;
}