Pagini recente » Borderou de evaluare (job #2059968) | Cod sursa (job #1191435) | Cod sursa (job #862645) | Cod sursa (job #2442042) | Cod sursa (job #3157697)
#include <bits/stdc++.h>
#define MAX 100000
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int v[MAX+1];
int m, n, c, x;
/*
lower_bound = cel mai din stanga element care este mai mare sau egal cu o valoare cautata
upper_bound = cel mai din stanga element care este mai mare decat o valoare cautata
*/
int main()
{
fin >> n;
for(int i=0; i<n; i++)fin >> v[i];
fin >> m;
for(int i=0; i<m; i++)
{
fin >> c >> x;
if(c==0)
{
int pos = upper_bound(v,v+n,x)-v-1;
if(v[pos]==x)fout << pos+1 << '\n';
else fout << -1 << '\n';
}
else if(c==1)
{
int pos = upper_bound(v,v+n,x)-v-1;
fout << pos+1 << '\n';
}
else if(c==2)
{
int pos=lower_bound(v,v+n,x)-v;
fout << 1+pos << '\n';
}
}
return 0;
}