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