Pagini recente » Cod sursa (job #2360426) | Cod sursa (job #2888957) | Cod sursa (job #1092203) | Cod sursa (job #161919) | Cod sursa (job #1828629)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n,m,i,c,x,v[100010];
int main()
{
f>>n;
for(i=1;i<=n;i++)
f>>v[i];
f>>m;
for(;m;m--)
{
f>>c>>x;
if(c==2)
g<<(int)(lower_bound(v,v+n+1,x)-v)<<'\n';
else
{
i=upper_bound(v,v+n+1,x)-v-1;
if(c==0&&v[i]!=x)
g<<"-1\n";
else
g<<i<<'\n';
}
}
return 0;
}