求助,样例通过,但是全部RE
查看原帖
求助,样例通过,但是全部RE
604665
sfx_01楼主2023/1/7 14:42

使用了lower_bound()之后,感觉逻辑上没有问题,报的应该是时间错误,不知道怎么修改了::>_<::

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

int n,m;
int a[100005];

int main( ){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=m;i++){
		int x;cin>>x;
		if(x<a[1]||x>a[n]){
			cout<<-1<<" ";
		}else{
			int k=lower_bound(a+1,a+n+1,x)-a;
			if(a[k]==x){
				cout<<k<<" ";
			}else{
				cout<<-1<<" ";
			}
		}
		
	}
}
2023/1/7 14:42
加载中...