789 数的范围
作者:
jy9
,
2024-08-23 13:36:52
,
所有人可见
,
阅读 3
#include <iostream>
using namespace std;
const int N=1e5+10;
int a[N];
int n, q;
int erfen1(int x){
int l = -1, r = n;
int mid;
while(l+1 != r){
mid = (l+r) >> 1;
if(x <= a[mid])r = mid;
else l = mid;
}
if(a[r] != x) return -1;
return r;
}
int erfen2(int x){
int l = -1, r = n;
int mid;
while(l+1 != r){
mid = (l+r) >> 1;
if(x >= a[mid])l = mid;
else r = mid;
}
if(a[l] != x)return -1;
return l;
}
int main(){
cin >> n >> q;
for (int i = 0; i < n; i ++ ){
cin >> a[i];
}
while(q--){
int t;
cin >> t;
cout << erfen1(t) << ' ' << erfen2(t) << endl;
}
return 0;
}