求助!!AcWing编译器样例过了为啥洛谷上全WA

P2249 【深基13.例1】查找

asdfg11 @ 2023-06-02 16:47:13

代码如下

#include <iostream>

using namespace std;

const int N = 1e6 + 10;

int q[N];
int n, m;

int main()
{
    scanf("%d%d", &n, &m);

    for(int i = 1; i <= n; i ++) scanf("%d", &q[i]);

    while(m --)
    {
        int x;
        scanf("%d", &x);
        int l = 1, r = n;
        while(l < r)
        {
            int mid = l + r >> 1;
            if(q[mid] >= x) r = mid;
            else l = mid + 1;
        }

        if(q[l] != x) printf("-1");
        else printf("%d ", l);
    }

    return 0;
}

by liupan2010 @ 2023-06-02 18:10:55

[帮你改了之后的记录。](https://www.luogu.com.cn/record/111819957)

by asdfg11 @ 2023-06-09 16:19:41

@liupan2010 我咋说全wa明明代码思路没错,原来是错在这了谢谢大佬提醒


|