[WA一个]玄关

P2249 【深基13.例1】查找

Mr_yang1 @ 2024-09-24 20:11:21

#include<bits/stdc++.h>
using namespace std;
int n,m,a[1000005],ds,in;
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    while(m--){
        scanf("%d",&ds);
        in=lower_bound(a,a+n,ds)-a;
        if(ds==a[in])printf("%d ",in);
        else printf("-1 ");
    }
}

by jade1695 @ 2024-09-24 20:21:45

#include<bits/stdc++.h>
using namespace std;
int n,m,a[1000010],ds,in;
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    while(m--){
        scanf("%d",&ds);
        in=upper_bound(a+1,a+1+n,ds-1)-a;
        if(ds==a[in])printf("%d ",in);
        else printf("-1 ");
    }
}

by jade1695 @ 2024-09-24 20:22:08

着样就过了


|