请问一下各位
查看原帖
请问一下各位
749272
ysqfirmament楼主2023/1/13 21:01
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll N=1e8;
ll n;
ll a[N];
int main()
{
    ios::sync_with_stdio(false);
    ll q;
    cin>>n>>q;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    while(q--)
    {
        ll x;
        cin>>x;
        ll ans=lower_bound(a+1,a+n+1,x)-a;
        if(x!=a[ans]) cout<<-1<<" ";
        else cout<<ans<<" ";
    }
}

为什么改成(int i=0;i<n;i++)和lower_bound(a,a+n,x)-a就不对

2023/1/13 21:01
加载中...