OTH_chinese_dragon @ 2024-08-05 11:43:49
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
long long a[N];
long long q[N];
int main(){
int n,m;
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= m; i++){
cin>>q[i];
int first=1,middle;
int half,len;
len = n;
while(len > 0){
half = len >> 1;
middle = first + half;
if(a[middle] < q[i]){
first = middle + 1;
len = len - half - 1;
}
else{
len = half;
}
}
if(a[first]!=q[i]){
cout<<"-1 ";
}else{
cout<<i<<" ";
}
}
return 0;
}
by AKCSPS @ 2024-08-05 11:49:22
@OTH_chinese_dragon 这是啥东西啊啊。谁二分这么写 直接:ll* id=lower_bound(a+1,a+n+1,x);
by OTH_chinese_dragon @ 2024-08-05 11:50:41
6,你咋来了?谢了哥
by 朱梓煊ZZX @ 2024-08-05 11:53:25
@OTH_chinese_dragon 你输出了i,要输出first
by OTH_chinese_dragon @ 2024-08-05 13:49:28
栓Q
by OHO_1 @ 2024-08-06 09:51:47
@AKCSPS 恍然大悟?