Pagini recente » Cod sursa (job #1538349) | Cod sursa (job #1555425) | Rating Interesat de Informatica (clandestin) | Cod sursa (job #530761) | Cod sursa (job #1411611)
#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=upper_bound(a.begin(),a.end(),x)-a.begin();
if(1<=y and y<=n) printf("%d \n", y);
}
if(tip==2) {
int y=lower_bound(a.begin(),a.end(),x)-a.begin();
if(1<=y and y<=n) printf("%d \n", y+1);
}
}
return 0;
}