Pagini recente » Cod sursa (job #2923067) | Cod sursa (job #2889533) | Cod sursa (job #61767) | Cod sursa (job #1231805) | Cod sursa (job #1127195)
#include<fstream>
#include<algorithm>
using namespace std;
int n,m,i,v[100007],t,x,y;
ifstream fi("cautbin.in");
ofstream fo("cautbin.out");
int main()
{
fi>>n;
for(i=1;i<=n;i++)
fi>>v[i];
fi>>m;
for(i=1;i<=m;i++)
{
fi>>t>>x;
if(t==2)
{
y=lower_bound(v+1,v+n+1,x)-v;
}
else
{
y=upper_bound(v+1,v+n+1,x)-v-1;
if(v[y]!=x && !t)y=-1;
}
fo<<y<<'\n';
}
fi.close();
fo.close();
return 0;
}