Pagini recente » Cod sursa (job #552684) | Cod sursa (job #431245) | Autentificare | Cod sursa (job #1034779) | Cod sursa (job #2073784)
#include<fstream>
using namespace std;
int v[100001];
int cautb0(int x, int n)
{
int position=0;
for(int power=20; power>=0; --power)
if(position+(1<<power)<=x && v[position+(1<<power)]<=n)
position+=1<<power;
return position;
}
int main()
{
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int N, M;
fin >> N;
for(int i=1; i<=N; i++)
fin >> v[i];
fin >> M;
for(int i=1; i<=M; ++i)
{
int type, x;
fin >> type >> x;
if(type==0)
if(v[cautb0(N,x)]!=x)
fout << "-1" << '\n';
else fout << cautb0(N, x) << '\n';
if(type==1)
fout << cautb0(N, x) << '\n';
if(type==2)
fout << cautb0(N, x-1)+1 << '\n';
}
return 0;
}