5 条题解

  • 0
    @ 2024-1-6 21:50:26
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    import java.util.regex.*;
    import java.math.*;
    public class Main {
        static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        static List<List<Integer>>res=new ArrayList<>();
        static int n,m;
        public static void main(String[] args) throws Exception {
            Scanner sc=new Scanner(System.in);
    n=Int();
    var arr=new int[n+1];
            for (int i = 1; i <= n; i++) {
                arr[i]=Int();
            }
            m=Int();
            for (int i = 1; i <= m; i++) {
                int x=Int();
            pw.print(  check(arr,x)+" ");
            }
    pw.flush();
        }
        public static int check(int[]arr,int x){
            var l=1;
            var r=n;
            while (l<r){
                int mid=(l+r)/2;
                if(arr[mid]>=x)r=mid;
                else
                    l=mid+1;
            }
         if(arr[l]!=x)
             return -1;
         else {
             while (arr[l+1]==arr[l])
                 l++;
                return l;
            }}
        public static String Line() throws Exception{
            String s = bf.readLine();
            return s;
        }
        public static int Int() throws Exception{
            st.nextToken();
            return (int) st.nval;
        }
        public static long Long() throws Exception{
            st.nextToken();
            return (long) st.nval;
        }
        public static double Double() throws Exception{
            st.nextToken();
            return (double)st.nval;
        }
    }
    

    信息

    ID
    576
    时间
    1000ms
    内存
    64MiB
    难度
    8
    标签
    (无)
    递交数
    74
    已通过
    12
    上传者