1 solutions

  • 0
    @ 2022-2-13 20:35:37
    #include<bits/stdc++.h>
    using namespace std;
    int n,l,r,m,k;
    const int N=1e8+5;
    int f[N];
    int find(int g){
    	l=1,r=n;
    	while(l<=r){
    		int mid=(l+r)/2;
    		if(f[mid]>=g){
    			r=mid-1;
    		}
    		else{
    			l=mid+1;
    		}
    	}
    	if(f[l]>=g){
    		return l;
    	}
    	else{
    		return -1;
    	}
    }
    int main(){
    	cin>>n;
    	for(int i=1;i<=n;i++){
    		cin>>f[i];
    	}
    	cin>>m;
    	while(m--){
    		cin>>k;
    		cout<<find(k)<<" ";
    	}
    	return 0;
    }
    • 1

    Information

    ID
    1232
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    3
    Tags
    # Submissions
    79
    Accepted
    43
    Uploaded By