Cod sursa(job #705726)
| Utilizator | Data | 4 martie 2012 20:38:21 | |
|---|---|---|---|
| Problema | Cautare binara | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.68 kb |
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n, a[1000000], q, x, y, i, *k;
int main()
{
f>>n;
for(i=1; i<=n; ++i) f>>a[i];
for(f>>q; q; --q)
{
f>>x>>y;
if(x==0)
{
k=upper_bound(a+1, a+n+1, y);
if(a[k-a-1]==y) g<<k-a-1<<"\n";
else g<<"\n";
//g<<k-a-1<<"\n";
}
else if(x==1)
{
k=upper_bound(a+1, a+n+1, y);
g<<k-a-1<<"\n";
}
else
{
k=lower_bound(a+1, a+n+1, y);
g<<k-a-1<<"\n";
}
}
}
