不知道为什么RE了

P2249 【深基13.例1】查找

CuteGhost @ 2023-03-22 16:57:18

Scanner和StreamTokenizer都是RE

package com.tao;

import java.io.IOException;
import java.util.Scanner;

public class CZ {
    static int n,m;
    static int[] arr = new int[100010];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        for(int i=1;i<=n;i++){
            arr[i] = sc.nextInt();
        }
        int x;
        for(int i=0;i<m;i++){
            x= sc.nextInt();
            int l =1,r = n ;
            while (l<r){
                int mid=(l+r)/2;
                if(arr[mid]<x){
                    l=mid + 1;
                }else r=mid;
            }
            if(arr[l]==x){
                System.out.print(l+" ");
            }else System.out.print(-1+" ");
        }
    }
}

|