题目描述
代码
#include<bits/stdc++.h>
using namespace std
;
const int maxn
= 1e5+50;
int n
,a
[maxn
],q
,t
;
vector
<pair
<int,int> >v
;
bool cmp(pair
<int,int> p1
,pair
<int,int> p2
){
return p1
.second
< p2
.second
;
}
int f(int t
){
int l
= 0,r
= n
;
while(l
< r
){
int mid
= l
+ (r
-l
)/2;
if(v
[mid
].second
>= t
){
r
= mid
;
}
else{
l
= mid
+1;
}
}
if(l
== n
)
return 0;
if(v
[l
].second
== t
){
return v
[l
].first
;
}
return 0;
}
int main(){
cin
>>n
;
for(int i
= 0;i
< n
;i
++){
cin
>>t
;
pair
<int,int> p
= make_pair(i
+1,t
);
v
.push_back(p
);
}
sort(v
.begin(),v
.begin()+n
,cmp
);
cin
>>q
;
for(int i
= 0;i
< q
;i
++){
cin
>>t
;
cout
<<f(t
)<<endl
;
}
return 0;
}
转载请注明原文地址:https://tech.qufami.com/read-247.html