RT
代码:
#include<bits/stdc++.h>
using namespace std;
struct node{
long long xx,yy;
}a[5000005];
bool flag;
long long i,n,m,x,mid;
bool cmp(node x,node y)
{
return x.xx<y.xx;
}
void search(long long l,long long r)
{
if(l>r){cout<<0<<endl;return;}
if(flag) return;
mid=(l+r+1)/2;
if(a[mid].xx==x){cout<<a[mid].yy<<endl;flag=true;return;}
if(a[mid].xx<x) search(mid+1,r);
if(a[mid].xx>x) search(l,mid-1);
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++){cin>>a[i].xx;a[i].yy=i;}
sort(a+1,a+1+n,cmp);cin>>m;
while(m--){flag=false;cin>>x;search(1,n);}
return 0;
}
帮我的好人一生平安啊awa