Pagini recente » Cod sursa (job #2136472) | Cod sursa (job #2534747) | Cod sursa (job #1522785) | Cod sursa (job #567557) | Cod sursa (job #1139678)
#include <fstream>
using namespace std;
ifstream in("cautbin.in");
ofstream out("cautbin.out");
int v[100001];
int n;
void caut0(int x)
{
int i, pas;
i = 0;
pas = 1 << 16;
while(pas)
{
if(i + pas <= n && v[i + pas] <= x)
i += pas;
pas /= 2;
}
if(v[i] == x)
out<<i<<'\n';
else
out<<"-1\n";
}
void caut1(int x)
{
int i, pas;
i = 0;
pas = 1 << 16;
while(pas)
{
if(i + pas <= n && v[i + pas] <= x)
i += pas;
pas /= 2;
}
out<<i<<'\n';
}
void caut2(int x)
{
int i, pas;
i = 0;
pas = 1 << 16;
while(pas)
{
if(i + pas <= n && v[i + pas] < x)
i += pas;
pas /= 2;
}
out<<i + 1<<'\n';
}
int main()
{
int m,i,t,x;
in>>n;
for(i = 1; i <= n; i++)
in>>v[i];
in>>m;
for(i = 1; i <= m; i++)
{
in>>t>>x;
if(!t)
caut0(x);
else if(t == 1)
caut1(x);
else
caut2(x);
}
return 0;
}