Pagini recente » Cod sursa (job #2600603) | Cod sursa (job #1557186) | Cod sursa (job #369495) | Cod sursa (job #1172074) | Cod sursa (job #1586841)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n,q,a[100005];
int main()
{ int i,t,x,p;
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
f>>q;
for(i=1;i<=q;i++)
{ f>>t>>x;
if (t==0)
{ p=upper_bound(a+1,a+n+1,x)-a-1;
if (a[p]!=x) p=-1;
}
if (t==1) p=upper_bound(a+1,a+n+1,x)-a-1;
if (t==2) p=lower_bound(a+1,a+n+1,x)-a;
g<<p<<"\n";
}
return 0;
}