Pagini recente » Cod sursa (job #2869111) | Cod sursa (job #1626668) | Cod sursa (job #3239594) | Cod sursa (job #1039535) | Cod sursa (job #2460760)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("cautbin.in");
ofstream out("cautbin.out");
const int N=100001;
int v[N];
int M,a,b,n;
int bin0(int x)
{
int st,dr,mj,last=-1;
st=0;
dr=n-1;
while ( st<=dr )
{
mj=(st+dr)/2;
if(x==v[mj]){
last=mj;
st=mj+1;
}
else if(x<v[mj])
dr=mj-1;
else
st=mj+1;
}
last++;
return last;
}
int bin1(int x)
{
int st,dr,mj,last=-1;
st=0;
dr=n-1;
while ( st<=dr )
{
mj=(st+dr)/2;
if(x>v[mj])
dr=mj-1;
else
st=mj+1;
}
return mj;
}
int bin2(int x)
{
int st,dr,mj,last=-1;
st=0;
dr=n-1;
while ( st<=dr )
{
mj=(st+dr)/2;
if(x<=v[mj])
dr=mj-1;
else
st=mj+1;
}
mj++;
return mj;
}
int main()
{
int i,j;
in>>n;
for( i=0; i<n; i++ )
{
in>>v[i];
}
in>>M;
for( i=0; i<M; i++ )
{
in>>a>>b;
if(a==0)
out<<bin0(b)<<'\n';
if(a==1)
out<<bin1(b)<<'\n';
if(a==2)
out<<bin2(b);
}
return 0;
}