本地没问题,也是二分,全RE
查看原帖
本地没问题,也是二分,全RE
1334250
hepingge10楼主2024/12/8 10:59
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i];
    while(m--){
        int x,l=0,r=n,t=0;
        bool f=1;
        cin>>x;
        while(l<=r){
            t=(r+l)/2;
            if(a[t]==x){cout<<t;f=0;break;}
            if(x>a[t])l=t+1;
            else r=t-1;
        }if(f)cout<<-1;
        cout<<' ';
    }return 0;
}
2024/12/8 10:59
加载中...