dfsgbear2 @ 2023-07-18 20:31:04
#include<bits/stdc++.h>
using namespace std;
int mid,m,n,a[100001],z,k;
int zy(int x,int y,int z){
while(x<y){
mid=(x+y)/2;
if(a[mid]>z)y=mid;
else x=mid+1;
}
return -1;
if(a[mid]==z)return mid;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
scanf("%d", &a[i]);
}
for(int i=0;i<m;i++){
cin>>z;
k=zy(0,n,z);
cout<<k;
}
}
by WA_sir @ 2023-07-18 20:37:01
return -1;
???
by dfsgbear2 @ 2023-07-18 20:40:37
@WA_sir ti mu shuo zhao bu dao jiu shu chu -1
by Terrible @ 2023-07-18 20:42:42
nin zhe ge cheng xu he ti jie ye xiang cha tai duo le ba?
xia mian shi gai hao de cheng xu shi fan:
#include<bits/stdc++.h>
using namespace std;
int mid,m,n,a[1000001],z,k;
int zy(int x,int y,int z){
while(x<y){
mid=(x+y)/2;
if(a[mid]>=z)y=mid;
else x=mid+1;
}
if(a[x]==z)return x;
return -1;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
scanf("%d", &a[i]);
}
for(int i=0;i<m;i++){
cin>>z;
k=zy(1,n,z);
cout<<k<<' ';
}
}
by Eason_cyx @ 2023-07-18 20:44:01
mo mo mo ni men dou zai gan shen me
by WA_sir @ 2023-07-18 20:51:16
shen me dong xi a?
by GoodLuckCat @ 2023-07-19 08:35:10
Da jia de dian nao dou da bu liao zhong wen le ma ? Wo hao xiang ye shi , zhong wen zha le
by GoodLuckCat @ 2023-07-19 08:35:39
Yan zheng ma liu liu qi liu chun shu zi ji