Pagini recente » Cod sursa (job #794516) | Cod sursa (job #103603) | Cod sursa (job #1923271) | Cod sursa (job #739013) | Cod sursa (job #2254351)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("cautbin.in");
ofstream fout("cautbin.out");
const int N_MAX = 100000 + 5;
int x[N_MAX], n;
int main() {
fin >> n;
for(int i = 1; i<=n; ++i)
fin >> x[i];
int m;
fin >> m;
while(m--){
int tip, val;
fin >> tip >> val;
if(tip == 0){
int poz = upper_bound(x+1, x+n+1, val) - x - 1;
if (x[poz] == val)
fout << poz << "\n";
else
fout << "-1\n";
} else if (tip == 1){
fout << upper_bound(x + 1, x + n + 1, val) - x - 1 << "\n";
} else if(tip == 2){
fout << lower_bound(x+1, x+n+1, val) - x << "\n";
}
}
return 0;
}