Pagini recente » Cod sursa (job #606062) | Cod sursa (job #2954900) | Cod sursa (job #1028172) | Cod sursa (job #957934) | Cod sursa (job #3314426)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int n,m;
vector<int> v(100100);
int main(){
int a,b;
ios::sync_with_stdio(false);
fin.tie(NULL);
fout.tie(NULL);
fin>>n;
for(int i=0; i<n; i++){
fin>>v[i];
}
fin>>m;
for(int i=0; i<m; i++){
fin>>a>>b;
if(a==0){
auto y=upper_bound(v.begin(),v.begin()+n,b);
if(y!=v.end() && v[y-v.begin()-1]==b){
fout<<y-v.begin()<<'\n';
}
else
fout<<-1<<'\n';
}
else if(a==1){
auto y=upper_bound(v.begin(),v.begin()+n,b);
if(y!=v.end()){
if(v[y-v.begin()-1]==b)
fout<<y-v.begin()<<'\n';
else if(v[y-v.begin()-2]<b){
fout<<y-v.begin()-1<<'\n';
}
else{
fout<<-1<<'\n';
}
}
else
fout<<-1<<'\n';
}
else{
auto y=lower_bound(v.begin(),v.begin()+n,b);
if(y!=v.end()){
if( v[y-v.begin()]==b)
fout<<y-v.begin()+1<<'\n';
else if(v[y-v.begin()+1]==b)
fout<<y-v.begin()+2<<'\n';
else
fout<<-1<<'\n';
}
else
fout<<-1<<'\n';
}
}
return 0;
}