yao4246 @ 2023-02-07 16:45:36
#include<iostream>
#include<cstdio>
using namespace std;
const int N=100100;
int a[N];
int n,m,x;
int binary_search(int x){
int l=0,r=n+1;
int mid;
while(l+1!=r){
mid=(l+r)/2;
if(a[mid]<x) l=mid;
else r=mid;
}
return a[r]==x ?r : -1;
}
int main(){
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
while(m--){
scanf("%d",&x);
printf("%d ",binary_search(x));
}
return 0;
}
by ProzacPainkiller @ 2023-02-07 16:51:07
数组开小了,你只开到
by ProzacPainkiller @ 2023-02-07 16:51:19
另外那叫 RE
by ProzacPainkiller @ 2023-02-07 16:51:43
开大了就过了
by yao4246 @ 2023-02-07 17:14:10
@eggome 谢谢你老师,我第一次用洛谷 还没有特别适应 谢谢