Pagini recente » Autentificare | Statistici Culda Nicolae (nicolaeculda) | Cod sursa (job #1963645) | Cod sursa (job #1317967) | Cod sursa (job #2201069)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int n,m;
int A[100002];
int x,y;
int res;
int main() {
fin>>n;
for(int i=1; i<=n; i++)
fin>>A[i];
fin>>m;
for(int i=1; i<=m; i++) {
fin>>x;
if(x==0){
fin>>y;
res=upper_bound(A+1,A+n+1,y)-A-1;
if(res<=n && res>=1 && A[res]==y)
fout<<res<<"\n";
else
fout<<"-1\n";}else if(x==1) {
fin>>y;
res=lower_bound(A+1,A+n+1,y+1)-A-1;
fout<<res<<"\n";
}else{
fin>>y;
res=upper_bound(A+1,A+n+1,y-1)-A;
fout<<res<<"\n";}}
return 0;
}