SHARE
TWEET

Untitled

a guest Oct 19th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int n;
  8.     cin >> n;
  9.     int m;
  10.     cin >> m;
  11.     vector <int> a;
  12.     for (int i = 0; i < n; i++) {
  13.         int z;
  14.         cin >> z;
  15.         a.push_back(z);
  16.     }
  17.      for (int i = 0; i < m; i++) {
  18.         int x;
  19.         cin >> x;
  20.         int l = 0;
  21.         int r = a.size();
  22.         while (r - l > 1) {
  23.             int m = (l + r) / 2;
  24.             if (x < a[m]) {
  25.                 l = m;
  26.             }else {
  27.                 r = m;
  28.             }
  29.         }
  30.         if (a[r] ! = x) {
  31.             cout << 0;
  32.         } else{
  33.             cout << r;
  34.         }    
  35.       }
  36.     return 0;
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top