You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
926 B
46 lines
926 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
const int N = 100010;
|
|
int n;
|
|
int q[N];
|
|
// 左闭右开 [ )
|
|
int lower_bound(int l, int r, int x) {
|
|
while (l < r) {
|
|
int mid = (l + r) >> 1;
|
|
if (q[mid] >= x)
|
|
r = mid;
|
|
else
|
|
l = mid + 1;
|
|
}
|
|
return l;
|
|
}
|
|
int upper_bound(int l, int r, int x) {
|
|
while (l < r) {
|
|
int mid = (l + r) >> 1;
|
|
if (q[mid] > x)
|
|
r = mid;
|
|
else
|
|
l = mid + 1;
|
|
}
|
|
return l;
|
|
}
|
|
int main() {
|
|
int T;
|
|
cin >> n >> T;
|
|
for (int i = 0; i < n; i++) cin >> q[i];
|
|
while (T--) {
|
|
int x;
|
|
cin >> x;
|
|
int i = lower_bound(0, n, x); //[0,n)
|
|
if (q[i] != x) {
|
|
puts("-1 -1");
|
|
continue;
|
|
}
|
|
printf("%d ", i);
|
|
i = upper_bound(0, n, x);
|
|
printf("%d\n", i - 1);
|
|
}
|
|
return 0;
|
|
}
|