python小白求助,全部TLE了,求大佬指正错误

P2249 【深基13.例1】查找

Beaut1ful @ 2024-03-05 20:02:52

n,m = map(int,input().split())
ls_num = input().split()
ls_Q = input().split()
for i in ls_Q:
    if i not in ls_num:
        print(-1,end=" ")
        continue
    lf = -1
    rt = n
    while lf+1 != rt:
        mid = (lf+rt)//2
        if int(ls_num[mid]) < int(i):
            lf = mid
        else:
            rt = mid
    else:
        if ls_num[lf] == i:
            print(lf,end=" ")
        elif ls_num[rt] == i:
            print(rt+1,end=" ")

|