Cod sursa(job #2925636)
Utilizator | Data | 15 octombrie 2022 20:28:51 | |
---|---|---|---|
Problema | Cautare binara | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 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 if(y==1)
G<<upper_bound(a,a+n,x)-a;
else
G<<lower_bound(a,a+n,x)-a+1;
return 0;
}