Cod sursa(job #1828629)
Utilizator | Data | 13 decembrie 2016 17:49:08 | |
---|---|---|---|
Problema | Cautare binara | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n,m,i,c,x,v[100010];
int main()
{
f>>n;
for(i=1;i<=n;i++)
f>>v[i];
f>>m;
for(;m;m--)
{
f>>c>>x;
if(c==2)
g<<(int)(lower_bound(v,v+n+1,x)-v)<<'\n';
else
{
i=upper_bound(v,v+n+1,x)-v-1;
if(c==0&&v[i]!=x)
g<<"-1\n";
else
g<<i<<'\n';
}
}
return 0;
}