Pagini recente » Cod sursa (job #1636877) | Cod sursa (job #3227950) | Cod sursa (job #567027) | Cod sursa (job #1039398) | Cod sursa (job #2137399)
#include <fstream>
#include<algorithm>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n,v[100001];
int main()
{
int x;
f>>n;
for(int i=1;i<=n;i++)
f>>v[i];
int m;
f>>m;
for(int i=1;i<=m;i++)
{
int x,y;
f>>x>>y;
if(x==0) {int z=upper_bound(v+1,v+n+1,y)-v-1; if(v[z]==y) g<<z<<endl; else g<<-1<<endl;}
if(x==1) {int z=upper_bound(v+1,v+n+1,y)-v-1;if(v[z]==y) g<<z<<endl; else g<<lower_bound(v+1,v+n+1,y)-v-1<<endl;}
if(x==2) {int z=lower_bound(v+1,v+n+1,y)-v; if(v[z]==y) g<<z<<endl; else g<<upper_bound(v+1,v+n+1,y)-v<<endl;}
}
return 0;
}