Pagini recente » Cod sursa (job #1653526) | Cod sursa (job #1787463) | Istoria paginii runda/acsdfg | Cod sursa (job #1635662) | Cod sursa (job #1411653)
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN=100001;
vector <int> a;
int n,m,tip,x;
int main()
{
freopen("cautbin.in","r",stdin);
freopen("cautbin.out","w",stdout);
scanf("%d", &n);
for(int i=1;i<=n;i++)
{
scanf("%d", &x);
a.push_back(x);
}
scanf("%d", &m);
for(int i=1;i<=m;i++)
{
scanf("%d%d", &tip, &x);
if(tip==0) {
int y=upper_bound(a.begin(),a.end(),x)-a.begin();
if(1<=y and y<=n and a[y-1]==x) printf("%d \n", y);
else printf("-1 \n");
}
if(tip==1) {
int y=lower_bound(a.begin(),a.end(),x+1)-a.begin();
printf("%d \n", y);
}
if(tip==2) {
int y=upper_bound(a.begin(),a.end(),x-1)-a.begin();
printf("%d \n", y+1);
}
}
return 0;
}