Pagini recente » Cod sursa (job #1329041) | Cod sursa (job #1803120) | Cod sursa (job #2862361) | Cod sursa (job #2281699) | Cod sursa (job #2218583)
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int a[100010];
int main(){
int n, m, x, y, t, i;
f >> n;
for(i = 1; i <= n; i++)
f >> a[i];
f >> m;
while(m --){
f >> t >> y;
if(t == 0){
x = upper_bound(a + 1, a + n + 1, y) - a - 1;
if(a[x] == y)
g << x << endl;
else
g << " -1 " << endl;
} else if(t == 1){
x = lower_bound(a + 1, a + n + 1, y + 1) - a - 1;
g << x << endl;
} else {
x = upper_bound(a + 1, a + n + 1, y - 1) - a;
g << x << endl;
}
}
return 0;
}