Pagini recente » Cod sursa (job #2285470) | Cod sursa (job #47007) | Cod sursa (job #3220658) | Cod sursa (job #730916) | Cod sursa (job #409497)
Cod sursa(job #409497)
#include<stdio.h>
#include<vector>
#include <algorithm>
using namespace std;
int n;
int v[100100];
void cit();
void go();
int main() {
freopen("cautbin.in", "r", stdin);
freopen("cautbin.out", "w", stdout);
cit();
go();
return 0;
}
void cit() {
scanf("%d",&n);
for(int i=1; i<=n;i++) {
scanf("%d", &v[i]);
}
}
void go() {
int m,i;
sort(v+1,v+n+1);
scanf("%d",&m);
for(i=1; i<=m;i++) {
int t,y,x;
scanf("%d%d",&t,&y);
if(t==0) {
int x = upper_bound(v + 1, v + n + 1, y) - v - 1;
if (x <= n && x >= 1 && v[x] == y)
printf("%d\n",x);
else
printf("-1\n");
}
if(t==1) {
int x = lower_bound(v + 1, v + n + 1, y + 1) - v - 1;
printf("%d\n",x);
}
if(t==2) {
int x = upper_bound(v + 1, v + n + 1, y - 1) - v;
printf("%d\n",x);
}
}
}