Pagini recente » Cristelnita - Al eigiler un es etsebrov | Cod sursa (job #2287235) | Cod sursa (job #683417) | Cod sursa (job #3281387) | Cod sursa (job #1364554)
#include <cstdio>
#include <vector>
#include <algorithm>
#define DIM 66013
using namespace std;
char buffer[DIM];
int poz = DIM - 1;
void Scanf(int &A){
A = 0;
while('0' > buffer[poz] || buffer[poz] > '9')
if(++poz == DIM)
fread(buffer,1,DIM,stdin),poz = 0;
while('0' <= buffer[poz] && buffer[poz] <= '9')
{
A = A * 10 + buffer[poz] - 48;
if(++poz == DIM)
fread(buffer,1,DIM,stdin),poz = 0;
}
}
vector<int> v;
int N,M;
void Read()
{
Scanf(N);
v.resize(N);
for(int i = 0; i < N; ++i)
Scanf(v[i]);
}
void Solve()
{
Scanf(M);
int tip,val;
for(int i = 1; i <= M; ++i)
{
Scanf(tip);
Scanf(val);
if(tip == 0)
{
int pz = upper_bound(v.begin(),v.end(),val) - v.begin();
if(0 <= pz && pz < N && v[pz-1] == val)
printf("%d\n",pz);
else
printf("-1\n");
continue;
}
if(tip == 1)
{
int pz = upper_bound(v.begin(),v.end(),val) - v.begin();
printf("%d\n",pz);
continue;
}
int pz = lower_bound(v.begin(),v.end(),val) - v.begin();
printf("%d\n",pz + 1);
}
}
int main()
{
freopen("cautbin.in","r",stdin);
freopen("cautbin.out","w",stdout);
Read();
Solve();
return 0;
}