Pagini recente » Cod sursa (job #2796054) | Cod sursa (job #679956)
Cod sursa(job #679956)
#include<fstream>
#include<algorithm>
#define NN 100001
using namespace std;
ofstream out("cautbin.out");
int v[NN],n,m,y,t,poz;
int main()
{
ifstream in("cautbin.in");
in>>n;
for(int i=1;i<=n;i++)
in>>v[i];
sort(v+1,v+n+1);
in>>m;
for(int i=1;i<=m;i++)
{
in>>t>>y;
if(t==0)
{
poz=upper_bound(v+1,v+n+1,y)-v-1;
if(poz<=n&&poz>=1&&v[poz]==y)
out<<poz<<'\n';
else
out<<-1<<'\n';
}
else if(t==1)
{
poz=lower_bound(v+1,v+n+1,y+1)-v-1;
out<<poz<<'\n';
}
else if(t==2)
{
poz=upper_bound(v+1,v+n+1,y-1)-v;
out<<poz<<'\n';
}
}
return 0;
}