Pagini recente » Cod sursa (job #2388684) | Cod sursa (job #727972) | Cod sursa (job #2976020) | Cod sursa (job #861067) | Cod sursa (job #1985394)
#include <fstream>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int n,i,v[100001],t,x,st,dr,m,mid;
int main()
{
fin>>n;
for(i=1;i<=n;i++)
fin>>v[i];
fin>>m;
for(i=1;i<=m;i++){
fin>>t>>x;
if(t==0){
st=1;
dr=n;
while(st<=dr){
mid=(st+dr)/2;
if(v[mid]==x)
st=mid+1;
else dr=mid-1;
}
if((st-1)==x)
fout<<st-1<<endl;
else fout<<"-1"<<endl;
}
if(t==1){
st=1;dr=n;
while(st<=dr){
mid=(st+dr)/2;
if(v[mid]==x)
st=mid+1;
else dr=mid-1;
}
fout<<st-1<<endl;
}
if(t==2){
st=1;dr=n;
while(st<=dr){
mid=(st+dr)/2;
if(v[mid]>=x)
dr=mid-1;
else st=mid+1;
}
fout<<st<<endl;
}
}
return 0;
}