救命全WA了感觉对着呢

P2249 【深基13.例1】查找

Arangest @ 2023-11-04 10:26:10

#include<iostream>
using namespace std;
int m,n,x;
int q[1000005];
int find(int x)
{
    int l =0,r=n-1;
      while(l<r)
        {
            int mid =(l+r)/2;
            if(q[mid]>=x)r=mid;
            else l=mid+1;
        }
        if(q[l]==x)return l;
        else return -1;
}
int main()
{
    scanf("%d %d",&n,&m);
    for(int i =0;i<n;i++)scanf("%d",&q[i]);
    for(int i =0;i<m;i++)
    {
       scanf("%d",&x);
       int j =find(x);
       printf("%d ",j);
    }
    return 0;
}

by Arangest @ 2023-11-04 10:27:34

@Arangest 我是蒟蒻


by Arangest @ 2023-11-04 10:29:20

@Arangest OK,已解决,下标从1开始


|