样例能过,题过不了,求助大佬

P2249 【深基13.例1】查找

xufeifeifei @ 2024-02-08 00:11:07

#include <bits/stdc++.h>

using namespace std;

int n,m,q;
   int a[100005];

int find(int q)
{
    int l=0;
    int r=n+1;
     while(l+1<r)
        {
            int mid=l+r >>1;
            if(a[mid]>=q)
              r=mid;
              else l=mid;
        }
    return a[r]==q?r:-1;
}
int main()
{    
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    cin >> a[i];
for(int i=1;i<=m;i++)
{cin >> q;
cout<<find(q)<<' ';
}
    return 0;   
    }

by _th_tw_on_ @ 2024-02-08 01:18:01

数组开小了

这么晚了还写题?


by xufeifeifei @ 2024-02-08 14:31:11

@pgl0321 感谢大佬,新年快乐


|