二分谁都知道主要是老师不让否则我也不会手打
总之就是先这么做再这么做再这么做再这么做然后这么做最后就出来了简单吧
#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000005];
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= m; i++)
{
int x;
scanf("%d", &x);
int lft = 0, rgh = n + 1;
while (lft < rgh)
{
int mid = (lft + rgh) / 2;
if (a[mid] >= x) rgh = mid;
else lft = mid + 1;
}
if (lft == 0 || lft == n + 1 || a[lft] != x) printf("-1 ");
else printf("%d ", lft);
}
return 0;
}
样例过了,就是点一是WA,最绝望的是**还不知道错哪里,就依仗各位大佬了 /抱拳/抱拳