amcbn

Colina

Nov 9th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. /* [A][M][C][B][N] / [K][R][I][P][6][8] */
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. typedef long long ll;
  5. const char sp = ' ', nl = '\n';
  6. const int MOD = 1999999973;
  7. ifstream fin("colina.in");
  8. ofstream fout("colina.out");
  9.  
  10. int bs(vector<pair<int, int>>& v, int x) {
  11.     int st = -1, dr = v.size();
  12.     while (dr - st > 1) {
  13.         int mij = (st + dr) / 2;
  14.         if (v[mij].first < x)
  15.             st = mij;
  16.         else
  17.             dr = mij;
  18.     }
  19.     if (dr == v.size() + 1 || v[dr].first != x)
  20.         return -1;
  21.     else
  22.         return dr;
  23. }
  24.  
  25. int main() {
  26.     ios::sync_with_stdio(0);
  27.     cin.tie(0), cout.tie(0);
  28.     int n, q, poz(1);
  29.     fin >> n >> q;
  30.     vector<pair<int, int>> v(n);
  31.     for (pair<int, int>& p : v) {
  32.         fin >> p.first;
  33.         p.second = poz++;
  34.     }
  35.     sort(v.begin(), v.end());
  36.     while (q--) {
  37.         int val, idx;
  38.         fin >> val;
  39.         idx = bs(v, val);
  40.         if (idx != -1) {
  41.             fout << "DA" << sp << v[idx].second;
  42.             if (idx + 1 < n)
  43.                 if (v[idx + 1].first == val)
  44.                     fout << sp << v[idx + 1].second;
  45.             fout << nl;
  46.         }
  47.         else
  48.             fout << "NU" << nl;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment