全WA求助(样例过了)
查看原帖
全WA求助(样例过了)
1009027
stils楼主2023/12/2 21:47
#include<bits/stdc++.h>
using namespace std;
const int N=1000006;
int n,m,a[N],b,tot=1;
int search(int x){
    int l=1,r=tot;
    while(l<=r){
        int mid=(l+r)/2;
        if(a[mid]==x)return mid;
        if(a[mid]<x)l=mid+1;
        if(a[mid]>x)r=mid-1;
    }
    return -1;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(x!=a[tot-1])a[tot++]=x;
    }
    for(int i=1;i<=m;i++){
        cin>>b;
        cout<<search(b)<<' ';
    }
    return 0;
}
2023/12/2 21:47
加载中...