Pagini recente » Cod sursa (job #1353378) | Cod sursa (job #2123741)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n,q,x,y,v[1000010],i,r;
int main()
{
f>>n;
for(i=1; i<=n; i++)
f>>v[i];
f>>q;
for(i=1; i<=q; i++)
{
f>>x>>y;
if(x==0)
{
r=upper_bound(v+1,v+n+1,y)-v-1;
if(r<=n&&r>=1&&v[r]==y)g<<r<<'\n';
else g<<"-1";
}
if(x==1)
{
r=lower_bound(v+1,v+n+1,y+1)-v-1;
g<<r<<'\n';
}
if(x==2)
{
r=upper_bound(v+1,v+n+1,y-1)-v-1;
g<<r+1<<'\n';
}
}
return 0;
}