zhaowufangnai @ 2024-03-07 23:21:05
#include<bits/stdc++.h>
using namespace std;
const int v = 1000010;
int a[v];
int num(int y,int z)
{
int left = 0;
int right = y;
while (left <= right)
{
int middle = (left+right) / 2;
if (a[middle] < z)
left = middle + 1;
else if (a[middle] > z)
right = middle - 1;
else if (a[middle] == z)
{
return middle;
break;
}
}
if (left > right)
return -1;
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int num( int y,int z);
int n = 0, m = 0;
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
{
int temp;
cin >> temp;
int x = num(n-1,temp);
if (x == -1)
cout << x << " ";
else if (x == 0)
cout << 1 << " ";
else
{
int i = 0;
for ( i = x-1;i>=0; i--)
{
if (a[i] != a[x])
{
x = i + 1;
break;
}
}
_ _ _
cout << x+1<<" ";
}
}
return 0;
}
by qusia_MC @ 2024-03-15 19:29:33
额你这个有一些极端情况会超时:
如果
by qusia_MC @ 2024-03-15 19:29:59
@zhaowufangnai
by zhaowufangnai @ 2024-03-16 15:11:30
@William2019 解决了,谢谢
by qusia_MC @ 2024-03-16 18:29:32
6