Advertisement
Josif_tepe

Untitled

Mar 2nd, 2024
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main() {
  5.     int n, q;
  6.     cin >> n >> q;
  7.     int niza[n];
  8.     int idx[55];
  9.     for(int i = 1; i <= 50; i++) {
  10.         idx[i] = 0;
  11.     }
  12.     for(int i = 0; i < n; i++) {
  13.         cin >> niza[i];
  14.         if(idx[niza[i]] == 0) {
  15.             idx[niza[i]] = i + 1;
  16.         }
  17.     }
  18.     for(int i = 0; i < q; i++) {
  19.         int x;
  20.         cin >> x;
  21.         cout << idx[x] << " ";
  22.         for(int j = 1; j <= 50; j++) {
  23.             if(idx[j] < idx[x] and idx[j] != 0) {
  24.                 idx[j]++;
  25.             }
  26.         }
  27.         idx[x] = 1;
  28.        
  29.     }
  30.     return 0;
  31. }
  32.  
  33. //n = 27 - 4 = 23
  34. // 89 145 42 20 4 16 37 58
  35. // 23 % 8 = 7
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement