Pagini recente » Cod sursa (job #1671205) | Cod sursa (job #3000450) | Cod sursa (job #2321267) | Cod sursa (job #2905775) | Cod sursa (job #1193254)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector < int > :: iterator upper,lower;
vector < int > V;
void Read()
{
int M,i,N,X,type,P;
scanf("%d",&N);
for (i=1;i<=N;++i)
{
scanf("%d",&X);
V.push_back(X);
}
sort(V.begin(),V.end());
scanf("%d",&M);
while (M--)
{
scanf("%d%d",&type,&X);
if (type==0)
{
upper = upper_bound(V.begin(),V.end(),X);
P=upper-V.begin();
if (P>=0 && P<N && V[P-1]==X)
{
printf("%d\n",P);
continue;
}
printf("-1\n");
continue;
}
if (type==1)
{
lower = lower_bound(V.begin(),V.end(),X+1);
P=lower-V.begin();
printf("%d\n",P);
continue;
}
upper = upper_bound(V.begin(),V.end(),X-1);
P=upper-V.begin()+1;
printf("%d\n",P);
}
}
int main()
{
freopen("cautbin.in","r",stdin);
freopen("cautbin.out","w",stdout);
Read();
return 0;
}