#include <cstdio>
#include <algorithm>

using namespace std;

struct Num
{
    int v;
    int oi;
};

Num arr[10000005];

bool comp(Num a, Num b)
{
    return a.v < b.v;
}

int f(int n, int tn)
{
    for(int i=0; j=n-1; i<=j; )
    {
        int md=i+(j-i)/2;
        if(arr[md].v == tn)
            return arr[md].oi;
        else if(arr[md].v<tn)
            i=md+1;
        else
            j=md-1;
    }
}

int main()
{
    int n,m;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&arr[i].v);
        arr[i].oi=i+1;
    }
    sort(arr,arr+n,comp);
    scanf("%d",&m);
    for(int i=0; i<m; i++)
    {
        int tn;
        scanf("%d",&tn);
        printf("%d ",f(n,tn));
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: