Advertisement
Hamoudi30

Untitled

Jul 16th, 2021
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pb push_back
  5. #define SZ(v) ((int)((v).size()))
  6. constexpr ll mod = 1e9+7;
  7. constexpr int N = 1e5+9;
  8. pair<int, int> a[N];
  9. void run () {
  10.     int n, q;
  11.     cin >> n >> q;
  12.     for (int i = 0; i < n; ++i) {
  13.         cin >> a[i].first;
  14.         a[i].second = i + 1;
  15.     }
  16.     sort(a, a + n);
  17.     while (q--) {
  18.         ll x;
  19.         cin >> x;
  20.         ll lo = 0, hi = n - 1;
  21.         ll ans = -1;
  22.         while (lo <= hi && ans == -1) {
  23.             ll mid = (lo + hi) / 2;
  24.             if (a[mid].first < x) {
  25.                 lo = mid + 1;
  26.             } else if (a[mid].first > x) {
  27.                 hi = mid - 1;
  28.             } else {
  29.                 ans = a[mid].second;
  30.             }
  31.         }
  32.         if (ans == -1)
  33.             cout << "No\n";
  34.         else
  35.             cout << "Yes " << ans << '\n';
  36.     }
  37. }
  38. int main () {
  39.     ios_base::sync_with_stdio(false);
  40.     cin.tie(nullptr);
  41.     cout.tie(nullptr);
  42. //    freopen("/home/hamoudi/clion/hello.in", "rt", stdin);
  43.     int tt;
  44.     tt = 1;
  45. //    cin >> tt;
  46.     while (tt--)
  47.         run();
  48. }
  49. /*
  50.  
  51.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement