Pagini recente » Cod sursa (job #2165972) | Cod sursa (job #3123765) | Cod sursa (job #3165526) | Cod sursa (job #2139667) | Cod sursa (job #2714513)
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream in("cautbin.in");
ofstream out("cautbin.out");
int n, m, V, x, pos;
int v[100005];
int main()
{
in >> n;
for(int i = 1; i <= n; ++ i)
in >> v[i];
in >> m;
for(int i = 1; i <= m; ++ i)
{
in >> V >> x;
pos = 0;
if(!V)
{
for(int j = (1 << 30); j > 0; j /= 2)
if(pos + j <= n && v[pos + j] <= x)
pos += j;
if(v[pos] == x) out << pos << '\n';
else out << -1 << '\n';
}
else if(V == 1)
{
for(int j = (1 << 30); j > 0; j /= 2)
if(pos + j <= n && v[pos + j] <= x)
pos += j;
out << pos << '\n';
}
else
{
for(int j = (1 << 30); j > 0; j /= 2)
if(pos + j <= n && v[pos + j] < x)
pos += j;
out << pos + 1 << '\n';
}
}
return 0;
}