Pagini recente » Cod sursa (job #2844144) | Cod sursa (job #2585748) | Cod sursa (job #1030132) | Cod sursa (job #2720244) | Cod sursa (job #2918271)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int n, m;
vector<int> v;
int main(){
fin >> n;
v.resize(n);
for(int i = 0; i < n; i++){
fin >> v[i];
}
sort(v.begin(), v.end());
fin >> m;
for(int i = 0, c, temp; i < m; i++){
fin >> c >> temp;
if(c == 0){
auto x = upper_bound(v.begin(), v.end(), temp);
if(*(x-1) == temp){
fout << x - v.begin() << '\n';
}else{
fout << "-1\n";
}
}else if(c == 1){
fout << upper_bound(v.begin(), v.end(), temp) - v.begin() << '\n';
}else{
fout << (lower_bound(v.begin(), v.end(), temp) - v.begin()) + 1 << '\n';
}
}
return 0;
}