Pagini recente » Cod sursa (job #2776054) | Cod sursa (job #1697421) | Cod sursa (job #1355725) | Cod sursa (job #2535386) | Cod sursa (job #3250536)
#include <fstream>
using namespace std;
ifstream cin ("cautbin.in");
ofstream cout ("cautbin.out");
int main()
{
int v[100001],n,i,st,dr,mij,x,m,c;
cin >> n;
for(i=1;i<=n;i++)
{
cin >> v[i];
}
cin >> m;
for(i=1;i<=m;i++)
{
cin >> c >> x;
if(c==0)
{
st=1;
dr=n;
while(st!=dr)
{
mij=(dr+st)/2;
if(x+1<=v[mij])
dr=mij;
else
st=mij+1;
}
if(v[st-1]==x)
cout << st-1 << endl;
else
cout << "-1"<< endl;
}
if(c==1)
{
st=1;
dr=n;
while(st!=dr)
{
mij=(dr+st)/2;
if(x+1<=v[mij])
dr=mij;
else
st=mij+1;
}
if(x>=v[n])
cout << n<< endl;
else
cout << st-1<< endl;
}
if(c==2)
{
st=1;
dr=n;
while(st!=dr)
{
mij=(dr+st)/2;
if(x<=v[mij])
dr=mij;
else
st=mij+1;
}
cout << st<< endl;
}
}
return 0;
}