Pagini recente » Cod sursa (job #3190507) | Cod sursa (job #271535) | Cod sursa (job #2354855) | Cod sursa (job #357575) | Cod sursa (job #2620299)
#include <iostream>
#include <fstream>
using namespace std;
int v[100001], n, cb1, cb2, cb3;
int cautbin1(int st, int dr, int x)
{
if(st > dr)
return cb1;
else
{
int m = st + (dr - st) / 2;
if(v[m] == x)
cb1 = m + 1;
if(v[m] > x)
return cautbin1(st, m - 1, x);
else
return cautbin1(m + 1, dr, x);
}
}
int cautbin2(int st, int dr, int x)
{
if(st > dr)
return cb2;
else
{
int m = st + (dr - st) / 2;
if(v[m] > x)
return cautbin2(st, m - 1, x);
else
{
cb2 = m + 1;
return cautbin2(m + 1, dr, x);
}
}
}
int cautbin3(int st, int dr, int x)
{
if(st > dr)
return cb3;
else
{
int m = st + (dr - st) / 2;
if(v[m] >= x)
{
cb3 = m + 1;
return cautbin3(st, m - 1, x);
}
else
return cautbin3(m + 1, dr, x);
}
}
int main()
{
ifstream f("cautbin.in");
ofstream g("cautbin.out");
f>>n;
int i;
for(i=0; i<n; i++)
f>>v[i];
int m;
f>>m;
for(i=0; i<m; i++)
{
int x, y;
f>>x>>y;
if(x == 0)
g<<cautbin1(0, n-1, y)<<endl;
if(x == 1)
g<<cautbin2(0, n-1, y)<<endl;
if(x == 2)
g<<cautbin3(0, n-1, y)<<endl;
}
return 0;
}