- //二分模板
- #include
- using namespace std;
- using ll = long long;
- const int N = 2e5 + 9;
-
- int a[N];
-
- void slove()
- {
- int n, q; cin >> n >> q;
- for (int i = 1; i <= n; ++i)cin >> a[i];
-
- while (q--)
- {
- int x; cin >> x;
- int l = 0, r = n;
- while (l + 1 != r)
- {
- int mid = (l + r) >> 1;
- if (a[mid] < x) l = mid;//l始终比mid小
- else r = mid;//r始终大于等于mid
- }
- if (a[r] == x) cout << r << ' ';
- else cout << -1 << ' ';
- }
- }
-
- int main()
- {
- ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- int t = 1;
- while (t--) slove();
- return 0;
- }