'commit'
This commit is contained in:
32
TangDou/LuoGuBook/P1918.cpp
Normal file
32
TangDou/LuoGuBook/P1918.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user