Pagini recente » Cod sursa (job #882971) | Cod sursa (job #2322747) | Cod sursa (job #1622438) | Rating Alexandru Bobeica (alexbobeica2003) | Cod sursa (job #1955596)
#include <fstream>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int n, m, vec[100000], STEP;
int main()
{
int i,step,tip,x;
fin>>n;
for(int s = 0; s < n; s++)
fin>>vec[n];
for(STEP = 1; STEP < n; STEP<<=1);
fin>>m;
for(int s = 0; s < m; s++)
{
fin>>tip>>x;
if(tip < 2)
{
for(step = STEP, i = step; step; step>>=1)
if(i + step <= n && vec[i + step] <= x)
i += step;
if(!tip && vec[i] != x)
fout<<"-1\n";
else
fout<<i<<"\n";
continue;
}
for(step = STEP, i = step; step; step>>=1)
if(i - step >= 0 && vec[i - step] >= x)
i -= step;
fout<<i<<"\n";
}
return 0;
}