Pagini recente » Cod sursa (job #1458315) | Cod sursa (job #2314952) | Cod sursa (job #2735283) | Cod sursa (job #80841) | Cod sursa (job #2098221)
#include <fstream>
#define limit 100005
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n, m, v[limit], pas;
int main()
{
int i, x, y, j, aux;
f >> n;
for (i = 1; i <= n; ++i) f >> v[i];
for (pas = 1; pas <= n; pas <<= 1);
f >> m;
for (j = 1; j <= m; ++j) {
f >> x >> y;
if (x < 2) {
for (i = 0, aux = pas; aux; aux >>= 1)
if (i + aux <= n && v[i + aux] <= y) i += aux;
if (!x && v[i] != y) g << "-1" << '\n';
else g << i;
continue;
}
for (i = n, aux = pas; aux; aux >>= 1)
if (i - aux >= 1 && v[i - aux] >= y) i -= aux;
g << i << '\n';
}
f.close();
g.close();
return 0;
}