Pagini recente » Cod sursa (job #474896) | Clasamentul arhivei Infoarena Monthly | Borderou de evaluare (job #1569605) | Istoria paginii runda/de_la_inceput | Cod sursa (job #999210)
Cod sursa(job #999210)
#include <iostream>
#include <fstream>
using namespace std;
int a[100000];
int caut0(int x,int n)
{
int i=0,pas=1<<16;
while (pas!=0)
{
if (a[i+pas]==x && (i+pas)<=n)
i+=pas;
pas/=2;
}
if (i==0)
i=-1;
return i;
}
int caut1(int x,int n)
{
int i=0,pas=1<<16;
while (pas!=0)
{
if (a[i+pas]<=x && i+pas<=n)
i+=pas;
pas/=2;
}
return i;
}
int caut2(int x,int n)
{
int i=0,pas=1<<16;
while (pas!=0)
{
if (i+pas<=n && a[i+pas]<x)
i+=pas;
pas/=2;
}
i+=1;
return i;
}
int main()
{
ifstream f ("cautbin.in");
ofstream g ("cautbin.out");
int n,m,i,x,intr;
f>>n;
for (i=1;i<=n;i++)
f>>a[i];
f>>m;
for (i=1;i<=m;i++)
{
f>>intr;
f>>x;
if (intr==0)
{
g<<caut0(x,n)<<"\n";
}
if (intr==1)
{
g<<caut1(x,n)<<"\n";
}
if (intr==2)
{
g<<caut2(x,n)<<"\n";
}
}
return 0;
}