Pagini recente » Cod sursa (job #884830) | Cod sursa (job #842695) | Cod sursa (job #2167939) | Cod sursa (job #1055676) | Cod sursa (job #1690882)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n,i,m,k,x,xx,y,v[10001];
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>>x>>y;
if(x==0)
{
xx=upper_bound(v+1,v+n+1,y)-v-1;
if(xx>=1&&xx<=n&&v[xx]==y)g<<xx<<'\n';
else g<<"-1"<<'\n';
}
else if (x==1)
{
xx=lower_bound(v+1,v+n+1,y+1)-v-1;
g<<xx<<'\n';
}
else if (x==2)
{
xx=upper_bound(v+1,v+n+1,y-1)-v-1;
g<<xx+1<<'\n';
}
}
return 0;
}