Pagini recente » Cod sursa (job #322886) | Cod sursa (job #3249408) | Cod sursa (job #3144519) | Cod sursa (job #1220209) | Cod sursa (job #1358338)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n,m,v[100005],x;
int main()
{
int i,j,c,aux;
f>>n;
for(i=1;i<=n;i++)
{
f>>v[i];
}
f>>m;
for(i=1;i<=m;i++)
{
f>>c>>x;
if(c==0)
{
aux= upper_bound(v+1,v+1+n,x)-v-1;
if(v[aux]==x && aux<=n && aux>=1)
g<<aux<<"\n";
else
g<<-1<<"\n";
}
if(c==1)
{
aux=lower_bound(v+1,v+1+n,x+1)-v-1;
g<<aux<<"\n";
}
if(c==2)
{
aux=upper_bound(v+1,v+1+n,x-1)-v;
g<<aux<<"\n";
}
}
return 0;
}