AcWing 789. 数的范围
原题链接
简单
作者:
NeonSean
,
2020-08-17 17:31:13
,
所有人可见
,
阅读 363
#include <iostream>
using namespace std;
const int N = 1e6 + 10;
int a[N];
int main() {
int n, q;
cin >> n >> q;
for (int i = 0; i < n; i++) cin >> a[i];
while (q--) {
int t;
cin >> t;
int l = 0, r = n - 1;
while (l < r) {
int mid = (l + r) >> 1;
if (a[mid] >= t) r = mid;
else l = mid + 1;
}
if (a[l] != t) {
cout << -1 << ' ' << -1 << endl;
}else {
int j = l;
while(a[l] == a[j]) j++;
cout << l << ' ' << j - 1 << endl;
}
}
return 0;
}