全wa,帮忙看下,谢谢

P2249 【深基13.例1】查找

impacter @ 2024-02-21 20:55:56

#include <bits/stdc++.h>
#define in int
using namespace std;

in a[100000010], n, m;

in find(in x)
{
    int l = 1, r = n;
    while(l < r)
    {
        int mid =l + (r - l) / 2;
        if(a[mid] >= x) r = mid - 1;
        else l = mid + 1;
    }    
    return a[l] == x ? l : -1;
}

int main()
{
    cin >> n >> m;
    for (in i = 1; i <= n; i++)
        cin >> a[i];
    for (in i = 1; i <= m; i++)
    {
        int q;
        cin >> q;
        int ans = find(q);
        cout << ans << " ";
    }
    return 0;
}

by weak_in_code @ 2024-02-21 21:20:46

r=mid


by weak_in_code @ 2024-02-21 21:21:27

@haoyuzhe2011


by impacter @ 2024-02-22 08:47:12

@xhx_st2025 好的,谢谢大佬


by impacter @ 2024-02-22 08:49:42

@xhx_st2025 过了,谢谢你!


|