Cod sursa(job #2905427)
Utilizator | Data | 21 mai 2022 14:45:27 | |
---|---|---|---|
Problema | Cautare binara | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream F("cautbin.in");
ofstream G("cautbin.out");
int a[100005],n,x,y,i;
int main()
{
for(F>>n;i<n;F>>a[i],++i);
for(F>>y;F>>y>>x;)
if(!y)
y=upper_bound(a,a+n,x)-a,G<<(y&&a[y-1]==x?y:-1)<<'\n';
else if(y==1)
G<<upper_bound(a,a+n,x)-a<<'\n';
else
G<<lower_bound(a,a+n,x)-a+1<<'\n';
return 0;
}