include
using namespace std;
int main() {
int m, n, num;
cin >> m >> n;
int arr[999999];
int s[999999];
for (int i = 0; i < m; i++) {
cin >> arr[i];
}
for (int i = 0; i < n; i++) {
cin >> num;
int st = 0;
int top = m - 1;
int found = 0;
while (st <= top) {
int mid = (st + top) / 2;
if (num > arr[mid]) {
st = mid + 1;
} else if (num < arr[mid]) {
top = mid - 1;
} else {
if (mid == 0 || arr[mid - 1] != num) {
s[i] = mid + 1;
found = 1;
break;
} else {
top = mid - 1;
}
}
}
if (!found) {
s[i] = -1;
}
}
for (int i = 0; i < n; i++) {
cout << s[i] << " ";
}
cout << endl;
return 0;
}
标签:arr,cin,int,每日,mid,else,num From: https://www.cnblogs.com/Wind52HZ/p/18546863