Pagini recente » Cod sursa (job #1882777) | Cod sursa (job #1689809) | Cod sursa (job #1472104) | Cod sursa (job #667793) | Cod sursa (job #1606581)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin ("cautbin.in");
ofstream fout ("cautbin.out");
#define MAXN 100050
int x[MAXN];
int N, M;
int main()
{
fin >>N;
for (int i = 1; i <= N; ++i)
fin >>x[i];
sort (x+1, x+N+1);
fin >>M;
for (int i = 1; i <= M; ++i)
{
int t, y;
fin >>t >>y;
switch (t)
{
case 0:
{int pos = upper_bound(x+1, x+1+N, y) - x - 1;
if (pos >= 1 && pos <= N && x[pos] == y)
fout <<pos <<'\n';
else
fout <<-1 <<'\n';
break;}
case 1:{
int pos = lower_bound(x+1, x+1+N, y+1) - x - 1;
fout <<pos <<'\n';
break;}
case 2:{
int pos = upper_bound(x+1, x+1+N, y-1) - x;
fout <<pos <<'\n';
break;}
}
}
return 0;
}