Josif_tepe

Untitled

Feb 23rd, 2026
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. using namespace std;
  5. int main () {
  6.     ios_base::sync_with_stdio(false);
  7.     int n;
  8.     cin >> n;
  9.    
  10.     vector<int> A(n), B(n), idx(n + 1);
  11.     for(int i = 0; i < n; i++) {
  12.         cin >> A[i];
  13.         idx[A[i]] = i;
  14.     }
  15.    
  16.     for(int i = 0; i < n; i++) {
  17.         cin >> B[i];
  18.     }
  19.    
  20.     int res = 0;
  21.     for(int i = 0; i < n; i++) {
  22.         if(A[i] != B[i]) {
  23.             res++;
  24.             int tmp = idx[B[i]], tmp2 = A[i];
  25.             swap(A[i], A[tmp]);
  26.             idx[A[i]] = i;
  27.             idx[tmp2] = tmp;
  28.            
  29.         }
  30.     }
  31.     cout << res << endl;
  32.  
  33.     return 0;
  34. }
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment