You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
742 B
32 lines
742 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
typedef long long LL;
|
|
typedef pair<int, int> PII;
|
|
const int N = 1e5 + 10;
|
|
int n, q;
|
|
PII a[N];
|
|
|
|
int main() {
|
|
cin >> n;
|
|
for (int i = 1; i <= n; i++) {
|
|
cin >> a[i].first;
|
|
a[i].second = i;
|
|
}
|
|
sort(a + 1, a + 1 + n); //PII默认排序是按first排的
|
|
cin >> q;
|
|
while (q--) {
|
|
int m;
|
|
cin >> m;
|
|
int l = 1, r = n;
|
|
while (l < r) {
|
|
int mid = l + r >> 1;
|
|
if (a[mid].first >= m) r = mid; // check()判断mid是否满足性质
|
|
else l = mid + 1;
|
|
}
|
|
if (a[l].first == m) cout << a[l].second << endl;
|
|
else cout << 0 << endl;
|
|
}
|
|
return 0;
|
|
} |