二分模板 84 pts WA #6 求调

P2249 【深基13.例1】查找

co7ahang @ 2023-05-13 21:41:26

#include<cstdio>
#include<algorithm>
typedef long long ll;
ll a[1000010],n,m;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<m;i++){
        ll k;
        scanf("%d",&k);
        ll ans=std::lower_bound(a,a+n,k)-a;
        if(a[ans]!=k) ans=-1;
        printf("%d ",ans);
    }
    return 0;
}

|