为啥全WA了

P2249 【深基13.例1】查找

wangpingyue @ 2024-11-10 11:50:41

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,m,a[N];
int find(int x)
{
    int l=1,r=n,mid;
    while(l<r)
    {
        mid=(l+r)/2;
        if(a[mid]>=x)
            r=mid;
        else
            l=mid+1;
    }
    if(a[l]==1)
        return l;
    else
        return -1;
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    while(m--)
    {
        int x;
        cin>>x;
        cout<<find(x)<<" ";
    }
    return 0;
}

by __int1024 @ 2024-11-10 11:56:12

@wangpingyue if(a[l]==1) 改成 if(a[l]==x)


by __int1024 @ 2024-11-10 11:56:48

@wangpingyue 求关


by wangpingyue @ 2024-11-10 12:02:56

@__int1024 蟹蟹,已关⌯>ᴗ o⌯


|