Wwz666 @ 2024-11-07 14:46:23
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int q = sc.nextInt();
int[] nums = new int[n];
for(int i = 0;i<n;i++){
nums[i] = sc.nextInt();
}
sc.nextLine();
String[] s = sc.nextLine().split(" ");
int i = 0;
while(q-->0){
int target = Integer.parseInt(s[i]);
int l = 0;
int r = n-1;
while(l<=r){
int mid = l+(r-l)/2;
if(nums[mid]>=target){
r = mid-1;
}else{
l = mid+1;
}
}
i++;
if(nums[l]==target) System.out.print(l+1+" ");
else System.out.print("-1 ");
}
}
}
by Estrella_Explore @ 2024-11-07 14:57:49
@Wwz666
友情提示:在 luogu 很少有人使用 Java,所以 Java 的求助帖很少有人回(我也不会 Java