Pagini recente » Cod sursa (job #2175816) | Cod sursa (job #1304439) | Cod sursa (job #725154) | Cod sursa (job #1275989) | Cod sursa (job #1690880)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n,i,v[1001],x,y,t,m,k;
int main()
{f>>n;
for(i=1;i<=n;i++)
f>>v[i];
sort(v+1,v+n+1);
f>>m;
for(k=1;k<=m;k++)
{f>>t>>y;
if(t==0)
{x=upper_bound(v+1,v+n+1,y)-v-1;
if(x>=1&&x<=n&&v[x]==y)g<<x<<'\n';
else g<<"-1"<<'\n';
}
else if(t==1)
{x=lower_bound(v+1,v+n+1,y+1)-v-1;
g<<x<<'\n';
}
else{
x=upper_bound(v+1,v+n+1,y-1)-v;
g<<x<<'\n';
}
}
return 0;
}