RE了,求助!

P2249 【深基13.例1】查找

zqw1234 @ 2024-09-22 07:05:34

#include<bits/stdc++.h>
#define maxn 150000
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int a[maxn], fw, n, m;;
using namespace std;
int __find(int x){
    int l = 1, r = n;
    while(l < r){
        int mid = l + ((r - l)>>1);
        if(a[mid] >= x) r = mid;
        else l = mid + 1;
    }
    if(a[l] == x) return l;
    else return -1;
}
int main(){
    fast;
    cin>>n>>m;
    for(int i = 1; i <= n; i++) cin>>a[i];
    sort(a, a + n);
    for(int i = 1; i <= m; i++){
        cin>>fw;
        int ans = __find(fw);
        cout<<ans<<' ';
    }
    return 0;
}
O(mlogn)难道输入输出还慢吗?

by Vivian_gao @ 2024-09-22 07:26:00

@zqw1234 自定义函数没有返回值


by Vivian_gao @ 2024-09-22 07:26:38

不对,眼瞎了,没看见


by zqw1234 @ 2024-09-22 08:39:40

没事了,ac了,发现数组开小了


|